T-SQL中如何通过查询结果给变量赋值?
存储过程里,如何将查询结果赋值给一个变量?
已知:USER表里ID为主键,列NAME为varchar型,如何将查询【SELECT NAME FROM USER WHERE ID = '12 '】的结果赋值给变量@NAME?
------解决方案--------------------DECLARE @NAME VARCHAR(40)
SELECT @NAME=NAME FROM USER WHERE ID = '12 '
------解决方案--------------------存储过程里,如何将查询结果赋值给一个变量?
已知:USER表里ID为主键,列NAME为varchar型,如何将查询【SELECT NAME FROM USER WHERE ID = '12 '】的结果赋值给变量@NAME?
declare @NAME as varchar(10)
SELECT @NAME = NAME FROM USER WHERE ID = '12 '