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