Concatenating Variables : Set « Transact SQL « SQL Server / T-SQL Tutorial






5> DECLARE @sql AS VARCHAR(MAX), @i AS INT;
6> SET @sql = '';
7> SET @i = 1;
8> WHILE @i <= 10
9> BEGIN
10>   SET @sql = @sql + 'PRINT ' + CAST(@i AS VARCHAR(10))
11>     + CHAR(13) + CHAR(10);
12>   SET @i=@i+1;
13> END
14> EXEC(@sql);
15> GO
1
2
3
4
5
6
7
8
9
10
1>








20.4.Set
20.4.1.Syntax for Variable Assignment with the SET Statement
20.4.2.Using SET to Assign Variables
20.4.3.Assign the function result to the variable
20.4.4.Return the variable value
20.4.5.Use set command to update a variable
20.4.6.Concatenating Variables
20.4.7.SET variable and column in one command