CREATE TABLE #test ( name VARCHAR(50), age INT ) INSERT INTO #test ( name, age ) VALUES ( 'lily', -- name - varchar(50) 28 -- age - int ) INSERT INTO #test ( name, age ) VALUES ( 'jack', -- name - varchar(50) 28 -- age - int ) INSERT INTO #test ( name, age ) VALUES ( 'snow', -- name - varchar(50) 28 -- age - int ) INSERT INTO #test ( name, age ) VALUES ( 'neal', -- name - varchar(50) 28 -- age - int ) DECLARE @NameList VARCHAR(50)='''lily'',''jack'',''neal''' EXEC ('SELECT * FROM #test WHERE name IN ('+@NameList+')') PRINT (@NameList)
http://blog.csdn.net/make1828/article/details/39498197