First, define variables
1, simple assignment 2, using the SELECT statement to assign a value of 3, using the UPDATE statement to assign a value
DECLARE @a int declare @user1 nvarchar (50) declare @user3 nvarchar
Set @a=5 Select @user1 = ' Zhang San ' update st_user set @user3 = Name where id=1
Print @a print @user1 print @user3
declare @user2 nvarchar (50)
Select @user2 = Name from St_user where id=1
Print @user2
Second, create a temporary table
CREATE TABLE #DU_User1
(
[ID] [int] not NULL, 1 inserts a data into the staging table insert into #DU_User1 (Id,name,[password]) VALUES (100, ' temporary ', ' 321 ');
[Name] [nvarchar] (5) Not NULL, 2 query data from St_user, populate to newly generated temporary table select * into #DU_User2 from St_user where id<8
[Password] [nvarchar] (max) NULL, 3 queries and union two temporary tables select * FROM #DU_User2 where id<3 union select * FROM #DU_User1
); 4 Delete temporary table drop table #DU_User1
SQL Server stored procedure Basic syntax