0

我正在关注这篇文章:SQL:INSERT INTO...VALUES..SELECT

我的问题是如何声明从 SELECT 语句中分配值的临时 @value1 ?我有类似的东西

CREATE PROCEDURE name
(
@arg1 as type1,
@arg2 as type2
)

AS
    @value1 = SELECT x from tabley WHERE <something>

    INSERT INTO Table(x,y,z) VALUES(@arg1,@arg2,@value1)

但我不知道在哪里声明和设置@value1??

4

3 回答 3

1
CREATE PROCEDURE name
(
@arg1 as type1,
@arg2 as type2
)

AS
DECLARE @value1 as type1

     SELECT @value1=x from tabley WHERE <something>

    INSERT INTO Table(x,y,z) VALUES(@arg1,@arg2,@value1)
于 2012-11-15T17:32:55.140 回答
0
SELECT @value1 := x from tabley WHERE <something>
于 2012-11-15T17:32:19.713 回答
0

DECLARE @value1 as type = (SELECT ...) 代替你的声明

于 2012-11-15T17:32:30.153 回答