为什么这个 T-SQL 函数总是返回 true?

发布于 2024-09-29 06:31:30 字数 538 浏览 1 评论 0原文

我写了这个函数,现在它总是返回 true...
有人可以帮助我吗?


Create FUNCTION dbo.ValidateBranch
(
    @BranchID   nvarchar(50),
    @Password   nvarchar(50)
)
RETURNS bit
AS
    BEGIN
    declare @Res bit

    if exists(Select * From TPasswords Where (BranchID = @BranchID) and (isSecurity = 0) and (Pass = @Password)) 
        set @Res = 1
    else
        set @Res = 0



    RETURN @Res
    END

我这样称呼:


bool isValidBranch = taQueries.ValidateBranch(IDBranch, PasswordTextBox.Text) ?? false;

I wrote this function and now its always returning true...
can anybody help me?


Create FUNCTION dbo.ValidateBranch
(
    @BranchID   nvarchar(50),
    @Password   nvarchar(50)
)
RETURNS bit
AS
    BEGIN
    declare @Res bit

    if exists(Select * From TPasswords Where (BranchID = @BranchID) and (isSecurity = 0) and (Pass = @Password)) 
        set @Res = 1
    else
        set @Res = 0



    RETURN @Res
    END

and i'm callign like so:


bool isValidBranch = taQueries.ValidateBranch(IDBranch, PasswordTextBox.Text) ?? false;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2024-10-06 06:31:30

T-SQL 代码看起来不错 - 如何“始终返回 true” - 在 SQL Mgmt Studio 中,或者从您的应用程序调用此函数?

你是如何调用这个函数的,你能给我们看看那段代码吗?

我很快重新创建了设置,就我而言,在 SQL Server 2008 R2 上,当我像这样调用此函数时,它工作得很好:

SELECT dbo.ValidateCenter('Center1', 'Pwd1')  -- return 1 
SELECT dbo.ValidateCenter('Center1', 'Pwd1333')  -- return 0

The T-SQL code seems fine - how do you "always get back true" - in SQL Mgmt Studio, or from your app calling this function??

How are you calling this function, can you show us that piece of code??

I quickly recreated the setup and in my case, on SQL Server 2008 R2, it works just fine when I call this function like this:

SELECT dbo.ValidateCenter('Center1', 'Pwd1')  -- return 1 
SELECT dbo.ValidateCenter('Center1', 'Pwd1333')  -- return 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文