DECLARE @orderid int,
@productid int,
@deliverdate datetime,
@copys int,
@count int,
@lastmonth datetime
SET @count=0;我这样定义,调试的时候,都提示我输入参数我就是想要select出来赋值给这个变量。。该怎么做呢?发现跟oracle相差还是蛮大的。。请教。。
@productid int,
@deliverdate datetime,
@copys int,
@count int,
@lastmonth datetime
SET @count=0;我这样定义,调试的时候,都提示我输入参数我就是想要select出来赋值给这个变量。。该怎么做呢?发现跟oracle相差还是蛮大的。。请教。。
你是想说申明一个变量,用select查询表中的内容,然后把查询出来的符合的内容赋值给该变量呀?
declare @count int
select @count=count(1) from table
-- t-sql 中没有类似 pl/sql 的 &name ,不能在语句运行时输入,而需要事先在 t-sql 语句中声明变量,并为变量赋值。
declare @emp_id int, @fname varchar(25);
set @emp_id=100;
select @fname=first_name from employees where employee_id=@emp_id;
print @fname;-- 类似的 pl/sql 语句
set serveroutput ondeclare fname varchar2(25);
begin
select first_name into fname from employees where employee_id=&emp_id;
dbms_output.put_line(fname);
end;
/
法二: select @a=a from tb where c='c' --查询时若有多条记录,以最后一条记录来赋值