1.DECLARE。。
声明变量,@name Type
2.SET
SET @num=value 一个SET只能对应一个变量赋值
3.SELECT
(1)SELECT @num=value (2)SELECT @num = SELECT num FROM tableName WHERE XX ='XX' (3)SELECT @num1=value1 , @ num2=value2,...
例如:
BEGIN; DECLARE @yxbz varchar(1),@gsdm varchar(20),@lenderid varchar(25);--声明变量 --变量赋值-- SET @yxbz='Y'; SELECT @gsdm='33288',@lenderid = '1355'; --引用变量-- SELECT * FROM dm_gsxx WHERE gsdm=@gsdm AND lenderid=@lenderid; UPDATE dm_gsxx SET lenderid = '-1' WHERE lenderid = @lenderid; end;