Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sql inÎÊÌâ

listidÊÇintÊý¾Ý
declare @listid nvarchar(100)
set @listid='(1,2,3,7,9,10)'
select * from forums where listid in(@listid)ʱÌáʾÈçÏ´íÎó£º
ÔÚ½« nvarchar Öµ '(1,2,3,7,9,10)' ת»»³ÉÊý¾ÝÀàÐÍ int ʱʧ°Ü¡£

µ«
declare @sql nvarchar(200)
declare @listid nvarchar(100)
set @listid='(1,2,3,7,9,10)'
set @sql='select * from forums where listid in(' + @listid + ')'
exec(@sql)
¾Í²»»áÓÐ´í¡£

listidÊÇintÊý¾Ý
declare @listid nvarchar(100)
set @listid='(1,2,3,7,9,10)'
select * from forums where listid in(@listid)ʱÌáʾÈçÏ´íÎó£º
ÔÚ½« nvarchar Öµ '(1,2,3,7,9,10)' ת»»³ÉÊý¾ÝÀàÐÍ int ʱʧ°Ü¡£

µ±È»À²,Õâ¸ö»áĬÈÏת³ÉLISTIDÀàÐÍ,ת²»¹ý¾Í±¨´íÁË,
ÓÃCHARINDEX»ò¶¯Ì¬EXEC

charindexÎÒÊÔ¹ý£¬µ«µ±@listid='12'ʱ
»á°Ñlistid=1,2,12µÄ¶¼»áÁгöÀ´

SQL code:
--TRY
select * from forums where charindex(','+ltrim(listid)+',',','+@listid+',')


ÒýÓÃ
charindexÎÒÊÔ¹ý£¬µ«µ±@listid='12'ʱ
»á°Ñlistid=1,2,12µÄ¶¼»áÁгöÀ´

CHARINDEX(','+LISTID+',',','+@LISTID+',')>0

ÒýÓÃ
SQL code--TRYselect*from forumswherecharindex('


Ïà¹ØÎÊ´ð£º

ÇóSQL£¿

´ó¼ÒºÃ£¬ÇëÎÊÔÚ±íMÖÐÓÐ×ֶΣºa b c d e 
ÎÒÏë²é³öÆäÖÐÂú×ãÏÂÃæÈÎÒâÒ»ÏîµÄÊý¾Ý£¬1.×Ö¶Îa µÄÖµ²»ÊÇ ¡®Êé»ò±Ê»ò±¾¡¯ÖÐÈÎÒ»£¬2.aΪÊéµÄʱºò×Ö¶Îb,cÊÇ¿Õ;3.µ±aֵΪ±ÊµÄʱºòdÊÇ¿Õ;4.µ±aΪ±¾µÄʱºòb,d,e¶¼ÊÇ¿Õ;5.È ......

sqlÊý¾Ý¸²¸Ç£¡

ÔõôʹÎÒÿ´Î²»ÊǸüÐÂÊý¾Ý¿â
¶øÊǸ²¸ÇÉϴεÄËùÓмǼÄØ£¡
ÒòΪÓÐʱºòʱ¼äÌõ¼þ²»Í¬
SQL code:

select * from hwouttb where
CAST(REPLACE(REPLACE(REPLACE(outdate,'Äê','-' ),'ÔÂ','-'),'ÈÕ','') AS ......

Çë½ÌÒ»¸öSQLÓ¦ÓÃÎÊÌâ

ÓÐʱºòÔÚÊý¾ÝÖвéѯÊý¾ÝµÄʱºò¿¼ÂÇÐÔÄÜÎÊÌ⣬»á½«¸´ÔÓÓï¾ä²ð·Ö»ò½èÓÃÁÙʱ±íÀ´¶à´Î²éѯ×îÖյõ½ÏëÒªµÄÊý¾Ý£¬ÏÖÔÚ½«ÕâЩ²éѯÄÚÈÝ×ö³É±¨±í£¬ÐèҪд¸öÓï¾äÒ»ÆøºÇ³É¡£
ÎÒÏëÎʵÄSQLÊÇ·ñ¿ÉÒÔÔÚ²éѯÓï¾äÒ»½áÊøºó£¬ÔÙ×Ô¶¯Ô ......

ÇóÕâ¾äSqlÈçºÎÀí½â

create table [¿Í»§ÁªÏµ±í]([¿Í»§±àºÅ] varchar(2),[ÁªÏµÈÕÆÚ] datetime,[ÁªÏµÄÚÈÝ] int)
insert [¿Í»§ÁªÏµ±í]
select 'aa','2009/01/01',111 union all
select 'bb','2009/02 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ