關于SQL的查找符合日期的記錄(100分)

  • 主题发起人 主题发起人 leo1
  • 开始时间 开始时间
L

leo1

Unregistered / Unconfirmed
GUEST, unregistred user!
dm0.pro1qry.sql.add('delete product1 where (day0 >= +'''+datetimepicker1.datetime+''') and (day0 <= +'''+datetimepicker2.datetime+''')');
這一句如何變化數據類型﹐day0是日期型字段﹐我想查找兩個日期之間的記錄﹐如何表達?
 
datetimepicker1.Date 取出的就是日期类型的数据(不包含时间)

datetimepicker1.Time 取出的就是时间类型的数据(不包含日期)
 
sql.clear;
sql.add('select * from 表 where (字段名 between :n1 and :n2)');
Parameters.parambyname('n1').Value :=datetostr(datetimepicker1.date);
Parameters.parambyname('n2').Value :=datetostr(datetimepicker2.date);
 
dm0.pro1qry.sql.add('delete product1 where (day0 >= +'''+datetimepicker1.datetime+''') and (day0 <= +'''+datetimepicker2.datetime+''')');
這一句如何變化數據類型﹐day0是日期型字段﹐我想查找兩個日期之間的記錄﹐如何表達?

你參考一下:
其中使用的Cast與Substring函數主要是讓日期中的時間去掉。(a.CurDate為日期型字段)
S:=' select Count(*) from SchStatus a, Schedule b where a.Single_No=b.Single_No and b.Code_No='+''''+Code_No+''''+
' and a.Single_No<>'+''''+Query3.FieldByName('Single_No').AsString+''''+
' and a.Node in ("P","Q","R","S","T","U","V","X")';
S:=S+' and ((a.CurDate>Cast(substring('+''''+DatetimeToStr(DbDateTimePicker2.Date)+''''+',1,11) as datetime) and a.CurDate<Cast(substring('+''''+DatetimeToStr(DbDateTimePicker3.Date)+''''+
',1,11) as datetime)) or (a.CurDate=Cast(substring('+''''+DatetimeToStr(DbDateTimePicker2.Date)+''''+',1,11) as datetime) and a.Node>='+''''+copy(DBComboBox2.Text,1,1)+''''+
' ) or (a.CurDate=Cast(substring('+''''+DatetimeToStr(DbDateTimePicker3.Date)+''''+',1,11) as datetime) and a.Node<'+''''+copy(DBComboBox3.Text,1,1)+''''+'))';
 
后退
顶部