@id=2 ¸ù¾Ýselect * from table where @id in (sortpath)²éѯËùÓÐsortpathÖк¬ÓÐ2µÄ¼Ç¼£¬ÏÔʾ ½« nvarchar Öµ '1,2,7' ת»»ÎªÊý¾ÝÀàÐÍΪ int µÄÁÐʱ·¢ÉúÓï·¨´íÎó
Èç¹ûʹÓÃselect * from table where @id in (1,2,7)¾Í²»»áÓдíÎó
select * from table where @id in (sortpath)Õâ¸öÓï¾ä¸ÃÔõô¸ÄÄØ£¿Ã»¿´¶®Ê²Ã´Òâ˼ ¼ñÖ÷ÒªµÄÀ´£¡ Êý¾Ý¿âʲôÑù£¡ ÏëҪʲôÑùµÄ½á¹û ¶¯Ì¬sqlÓï¾ä
SQL code: declare @str varchar(20) set @str='2,4,6' exec('select * from master.dbo.spt_values WHERE number IN('+@str+')')
INÔõôÓÃÄØ£¿
sortpathΪnvarcharÀàÐÍ£¬Èç'1,2,7' @idΪÕûÊý
ʵÏÖselect * from table where @id in sortpathµÄ¹¦ÄÜ£¬ÔÚ´æ´¢¹ý³ÌÖУ¬ÕýÈ·µÄSQLÓï¾ä¸ÃÔõôд select * from table where charindex(@id,sortpath) > 0
ͬÒâ2Â¥£¬¶¯Ì¬×éºÏsql Óï¾ä asp.net ¸ßÊÖáÈÆðȺ3 ÑûÇëÄã¼ÓÈë ȺQQ:90711635 Ò