[英]How to select values from a table (SQL Server database) into a parameter (Stored Procedure)?
I am trying to select few values from a table (SQL Server database) into few parameters (Stored Procedure) and here's what I did: 我正在尝试从表(SQL Server数据库)中将几个值选择为几个参数(存储过程),这是我所做的:
CREATE PROCEDURE [dbo].ValidateStudent
(
@UserName varchar(50),
@Password varchar(50),
@Yes_No int OUTPUT,
@StudentId int OUTPUT
)
AS
SET NOCOUNT ON;
SELECT @Yes_No = COUNT(*)
FROM Student
WHERE (UserName = @UserName) AND (Password = @Password)
SELECT @StudentId = StudentId
FROM Student
WHERE (UserName = @UserName) AND (Password = @Password)
Since I am not sure whether it is the right way to achieve what I have mentioned, I need to know few things: 由于我不确定实现上述内容的正确方法,因此我需要了解的几件事:
Please tell me if the above query is valid and if not then suggest me with the valid query for the same. 请告诉我以上查询是否有效,如果无效,则建议我使用相同的有效查询。
Thanks, 谢谢,
You can populate both parameter values with one SELECT
您可以使用一个
SELECT
填充两个参数值
CREATE PROCEDURE [dbo].ValidateStudent
(
@UserName varchar(50),
@Password varchar(50),
@Yes_No int OUTPUT,
@StudentId int OUTPUT
)
AS
SET NOCOUNT ON;
SELECT @StudentId = StudentId, @Yes_No = COUNT(1)
FROM Student
WHERE (UserName = @UserName) AND (Password = @Password)
GROUP BY StudentId
That said, wouldn't the value of @Yes_No always be 1, unless you have more than one student with the same UserName
and Password
? 就是说,@ Yes_No的值是否不会始终为1,除非您有多个具有相同
UserName
和Password
学生?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.