°ÝÃD:
select datediff(day,'20040910','20040920') --³o¥y¥i¥H°õ¦æ
--¦Ó¤U±³o¥y¤£¯à°õ¦æ(¦³®É¤]¥i¥H°õ¦æ)
--sub_para¬°varchar(8),¿ù»~¸ê°T¬O¡G±q¦r¦êÂà´«¬° datetime ®Éµo¥Í»yªk¿ù»~¡C
select * from T_SUB
where item_local_code='03004'
and datediff(day,sub_para,getdate())=29
and (sub_del_flag<>1)
--¦Ó¥B¤£¯à°õ¦æªº®ÉÔ,³oÓ»y¥y¤£·|ªð¦^¥ô¦ó°O¿ý¶°
select * from t_sub
where item_local_code='03004'
and isDate(sub_para)=0
-------------------------------------------------------------------------
--ì¦],ªí¤¤³Ð«Øªº¯Á¤Þ¼vÅT¤F±ø¥óªº°õ¦æ¶¶§Ç
--¾ÉP¥ý°õ¦æ¤F datediff(day,sub_para,getdate())
--¤U±ªº´ú¸Õ»¡©ú¤F³oÓ°ÝÃD
--´ú¸Õªí¤Î¸ê®Æ
create table tb(
item_local_code char(5),
sub_del_flag int,
sub_para varchar(10),
constraint PK_t primary key(sub_para,item_local_code)
)
insert tb select '03004',1,'2003-1-1'
union all select '03005',1,'2003a1-1'
go
--¬d¸ß»y¥y
select * from (
select * from tb
where item_local_code='03004'
and sub_del_flag<>0
and isdate(sub_para)=1
) A where datediff(day,sub_para,getdate())>29
go
--§R°£´ú¸Õ
drop table tb
/*--´ú¸Õµ²ªG
item_local_code sub_del_flag sub_para
--------------- ------------ ----------
03004 1 2003-1-1
¦øªA¾¹: ®ø®§ 241¡A¯Å§O 16¡Aª¬ºA 1¡A¦æ 3
±q¦r¦êÂà´«¬° datetime ®Éµo¥Í»yªk¿ù»~¡C
--*/