W wbing Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-03 #1 请问,如何按时间在sqlserver中查询记录?比如查询2002年12月3日 以前的记录。。。直接用日期型可以吗?
T tomol Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-03 #2 select * from tabel1 where datetimeField<='2002-12-3'
W watter Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-03 #4 在SQL Server中,日期型数据在Sql语句中要用单引号加以标识
W wbing Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-03 #5 select * from tabel1 where datetimeField<='2002-12-3' 我试过了,是可以的,不过假如我要动态改变日期 怎么办?select * from tabel1 where datetimeField<='2002-12-3'已经是字符串了,怎么再给日期加上''?请在我一些 指教。。
select * from tabel1 where datetimeField<='2002-12-3' 我试过了,是可以的,不过假如我要动态改变日期 怎么办?select * from tabel1 where datetimeField<='2002-12-3'已经是字符串了,怎么再给日期加上''?请在我一些 指教。。
W watter Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-25 #6 你要保证送到SQL的字符串中日期部分也是有单引号的, 应该是这样: Query1.SQl.Clear; Query1.SQl.Add('select * '); Query1.SQl.Add('from tabel1 '); Query1.SQl..Add('where datetimeField<='''+varDateTime+''''); Query1.Open;
你要保证送到SQL的字符串中日期部分也是有单引号的, 应该是这样: Query1.SQl.Clear; Query1.SQl.Add('select * '); Query1.SQl.Add('from tabel1 '); Query1.SQl..Add('where datetimeField<='''+varDateTime+''''); Query1.Open;
I IWTBAH Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-25 #7 最好使用参数 Query1.SQl.Clear; Query1.SQl.Add('select * from tabel1 '); Query1.SQl.Add('where datetimeField<=datetime'); Query1.SQl.parambyname('pdatetime').asdatetime =vardatetime; Query1.Open;
最好使用参数 Query1.SQl.Clear; Query1.SQl.Add('select * from tabel1 '); Query1.SQl.Add('where datetimeField<=datetime'); Query1.SQl.parambyname('pdatetime').asdatetime =vardatetime; Query1.Open;
Z zerg112879 Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-25 #8 建议用存储过程来做,declare一个@param为日期型的,然后付值. 若查找数据的话,同意上面的,但你可以在QUERY中写下代码,再在DELPHI中申明一个变量,用 strtodate()转换即可.
建议用存储过程来做,declare一个@param为日期型的,然后付值. 若查找数据的话,同意上面的,但你可以在QUERY中写下代码,再在DELPHI中申明一个变量,用 strtodate()转换即可.
Z zjjzcgao Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-27 #9 日期类型可以同watter, 如果是时间日期类型(2002-12-27 18:9:28),最好先取出来比较。
L liuxiaouo Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-27 #10 query1.close; query1.sql.clear; query1.sql.('select * from yourtable') Query1.sql.add('datetimeField>="'+formatdatetime('mm/dd/yyyy 00:00:00',DateTimePickerMindate.date)+'"'); Query1.sql.add('and datetimeField<="'+formatdatetime('mm/dd/yyyy 23:59:59',DateTimePickerMaxdate.date)+'"'); query1.open; 其中DateTimePickerMindate:TDateTimePicker; DateTimePickerMaxdate: TDateTimePicker;
query1.close; query1.sql.clear; query1.sql.('select * from yourtable') Query1.sql.add('datetimeField>="'+formatdatetime('mm/dd/yyyy 00:00:00',DateTimePickerMindate.date)+'"'); Query1.sql.add('and datetimeField<="'+formatdatetime('mm/dd/yyyy 23:59:59',DateTimePickerMaxdate.date)+'"'); query1.open; 其中DateTimePickerMindate:TDateTimePicker; DateTimePickerMaxdate: TDateTimePicker;
L liuxiaouo Unregistered / Unconfirmed GUEST, unregistred user! 2002-12-27 #11 query1.close; query1.sql.clear; query1.sql.('select * from yourtable') Query1.sql.add('where datetimeField>="'+formatdatetime('mm/dd/yyyy 00:00:00',DateTimePickerMindate.date)+'"'); Query1.sql.add('and datetimeField<="'+formatdatetime('mm/dd/yyyy 23:59:59',DateTimePickerMaxdate.date)+'"'); query1.open; 其中DateTimePickerMindate:TDateTimePicker; DateTimePickerMaxdate: TDateTimePicker;
query1.close; query1.sql.clear; query1.sql.('select * from yourtable') Query1.sql.add('where datetimeField>="'+formatdatetime('mm/dd/yyyy 00:00:00',DateTimePickerMindate.date)+'"'); Query1.sql.add('and datetimeField<="'+formatdatetime('mm/dd/yyyy 23:59:59',DateTimePickerMaxdate.date)+'"'); query1.open; 其中DateTimePickerMindate:TDateTimePicker; DateTimePickerMaxdate: TDateTimePicker;