SQL Server 2000表中的"申请日期"字段是日期时间型的,如何查询?(10分)

  • 主题发起人 主题发起人 sjm
  • 开始时间 开始时间
S

sjm

Unregistered / Unconfirmed
GUEST, unregistred user!
是这样:我在Select 语句中的Where 子句写"申请日期 like '%2006-11%'",主要想把2006年11月的记录查询出来,但却报错,请问应该如何写呢?谢谢!
 
这样吧,like '2006-11%'
 
'select * from 表 where 申请日期 = '+''''+ 2006-11 +'''' ;
 
日期的我从来没用过%
要不就用between and
 
'select * from 表 where 申请日期 = ''%'+ 2006-11 +'%''' ;
 
'申请日期'字段本身是日期时间型的,恐怕用字符串来凑不行吧?
 
procedure TFormsfq.Button3Click(Sender: TObject);
var
dataseperate,strCondition :string;
begin
//根据查询的选项查找出相应的数据。
dataseperate='''' ;
strCondition := ' where 预约日期= '+ dataseperate+ datetostr(dtp.Date)+dataseperate ;
if trim(Cmbjcys.Text) <> '' then
strCondition := strCondition + ' and 检查医生 like ''%' + cmbJCYS.Text + '%' + '''';
if trim(cmbxm.Text) <> '' then
strCondition := strCondition + ' and 类别=''' + cmbxm.Text + '''';
if trim(editxm.Text) <> '' then
strCondition := strCondition + ' and 姓名 like ''%' + editxm.Text + '%' + '''';
with adodsall do
begin
adodsall.Active := false;
adodsall.CommandText := 'select * from 预约检查表 ' + strCondition;
adodsall.Active := true;
end;
end;
 
这样应该明白了吧
 
select * from 表 where 申请日期 like '200611%'
 
'convert(char(6),申请日期,112) like '+'''+formatdatetime('yyyymm',rq.date)+'%'''
 
Select * From TableName From 申请日期 Between '2006-11-1' And '2006-11-30'
 
楼上的兄弟这个方法是可以,也可以用下面的这种方法.
Select * From TableName where year(申请日期)='2006' and month(申请日期)='11' 也是可以.
 
between '2006-11-01' and '2006-11-30'
 
日期格式用 > <就行了。
 
like '#2006-11%#'
在日期前后加 # 号即可!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
I
回复
0
查看
504
import
I
后退
顶部