在存储过程中创建 SQL 表变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31674067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:51:34  来源:igfitidea点击:

Creating a SQL table variable in a stored procedure

sqlstored-proceduressqlparameter

提问by Hari Chaudhary

I want to create SQL variable table in stored procedure which include this;

我想在包含这个的存储过程中创建 SQL 变量表;

Select a,b,c,d from **@tablename** where a=1 and c=0

How can do this with sp when creating sp?

创建 sp 时如何用 sp 做到这一点?

回答by Hari Chaudhary

You can declare table variable in SP as:

您可以将 SP 中的表变量声明为:

DECLARE @tablename TABLE(
    a INT,
    b INT,
    c INT,
    d INT);

SELECT * FROM @tablename;

回答by Ahmad Al ALloush

I hope this answer helps you

我希望这个答案对你有帮助

GO
CREATE PROCEDURE PrededureName
AS
BEGIN
DECLARE @tempTable TABLE
(
    a INT, 
    b INT,
    c INT,
    d INT
)
INSERT INTO @tempTable (a, b, c, d)
SELECT a, b, c, d FROM @tablename WHERE a=1 and c=0
END
GO;