gpt4 book ai didi

sql-server - SQL Server : how to create a stored procedure

转载 作者:行者123 更新时间:2023-12-02 00:05:30 25 4
gpt4 key购买 nike

我正在从一本书中学习sql,并且正在尝试编写一个存储过程,但我不相信我做得正确。以下方式在 Microsoft SQL 中无效吗?如果不是,那么什么时候有效(如果有效)?

create procedure dept_count(in dept_name varchar(20), out d_count integer)
begin
select count(*) into d_count
from instructor
where instructor.dept_name=dept_count.dept_name
end

我收到以下错误

Msg 156, Level 15, State 1, Procedure wine_change, Line 1 Incorrect syntax near the keyword 'in'.

最佳答案

T-SQL

/* 
Stored Procedure GetstudentnameInOutputVariable is modified to collect the
email address of the student with the help of the Alert Keyword
*/



CREATE PROCEDURE GetstudentnameInOutputVariable
(

@studentid INT, --Input parameter , Studentid of the student
@studentname VARCHAR (200) OUT, -- Output parameter to collect the student name
@StudentEmail VARCHAR (200)OUT -- Output Parameter to collect the student email
)
AS
BEGIN
SELECT @studentname= Firstname+' '+Lastname,
@StudentEmail=email FROM tbl_Students WHERE studentid=@studentid
END

关于sql-server - SQL Server : how to create a stored procedure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19947878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com