如何自定义输出/返回? [英] How can I customize the output / return?

查看:86
本文介绍了如何自定义输出/返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

USE [OJTTEST]
GO
/****** Object:  StoredProcedure [dbo].[sp_getUserAccess]    Script Date: 10/16/2013 11:56:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Michelle Rigor
-- Create date: 10/10/2013
-- Description:	get sp for user acess
-- =============================================
ALTER PROCEDURE [dbo].[sp_getUserAccess]
	(@UserName varchar (25),
	@Password varchar (25))
AS
DECLARE @return int
BEGIN
	SET NOCOUNT ON;
	IF (select AccessWord from UserAccess where UserName='%@UserName%' AND AccessWord ='%@Password%') = @Password 
            set @return = 1
        ELSE
            set @return = 0

END





我有这个存储过程。我希望我的输出为一(1)如果为真,零(0)如果为假。

这是关于用户是否有访问权限访问该网站。使用SQL Server Management Studio 2008.



I have this stored procedure. I want my output to be one(1) if true and zero(0) if false.
This is about the access of a user to the site if the user has access or not. Using SQL Server Management Studio 2008.

推荐答案

按如下方式修改存储过程,下面的代码将帮助您...

Modify your stored procedure as follows, The below piece of code will help you...
ALTER PROCEDURE [dbo].[sp_getUserAccess]
(
	@UserName varchar (25),
	@Password varchar (25),
	@Result varchar(5) output
)
AS
BEGIN
	SET NOCOUNT ON;
	IF (select AccessWord from UserAccess where UserName='%@UserName%' AND AccessWord ='%@Password%') = @Password 
            set @Result='One'
        ELSE
            set @Result='Zero' 
END



现在,执行以下步骤:


Now, Execute the above procedure as follows:

declare @CheckUserAccess varchar(5)
Execute [dbo].[sp_getUserAccess] 'Username Here','Password Here',@result = declare @CheckUserAccess output
print @CheckUserAccess 



示例:


Example:

declare @CheckUserAccess varchar(5)
Execute [dbo].[sp_getUserAccess] 'Dipesh','121',@result = declare @CheckUserAccess output
print @CheckUserAccess 



以上示例将打印 ONE 如果用户名和密码 EXIST 在表格中。

如果用户名和密码不存在,上面的例子将打印 ZERO / b>在表格中。


The above example will print ONE if username and password EXIST in table.
The above example will print ZERO if username and password DOES NOT EXIST in Table.


这篇关于如何自定义输出/返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆