First, Zou Jianli - below is test
- Test Data Declare @t Table (Columns 1 VARCHAR (10)) Insert Into @tselect 'a'union all select' d'union all select 'e'union all select' T'Union All Select 'S'Union All Select '5'Union all succ' 96 '
- Handling Declare @s varchar (8000), @ i Intselect @S = ', @ i = 1select @ s = @ S ', [Column ' Cast (@i as varchar) '] = '' 1 '' ', @ i = @ i 1From @tset @ s = substring (@ s, 2,8000) EXEC (' SELECT ' @ s)
/*--Test Results
Less Lee 1, 2, 3, 4, 5 columns, 5 columns, 6 columns 7 ---- ---- ---- ---- ---- ---- ---- A D e t s 5 96
- * /