0

这是我未编译的查询:

Select 1 from dbo.EmailAddresses e
    Inner Join Users u On e.UserID = u.UserID
        Where LOWER(EmailAddress) = @EmailAddress               
        And
    Case When @For = 1 Then e.JurisdictionID IS NOT NULL  When @For = 2 Then e.AccountID IS NOT NULL  End

谁能告诉我在没有动态查询的情况下编写此查询的方法,即在字符串中构建查询?

4

2 回答 2

2

这应该有效:

Select 1 from dbo.EmailAddresses e
    Inner Join Users u On e.UserID = u.UserID
        Where LOWER(EmailAddress) = @EmailAddress               
        And (
            (@For = 1 AND e.JurisdictionID IS NOT NULL) OR
            (@For = 2 AND e.AccountID IS NOT NULL)
        )
于 2012-09-04T13:20:36.843 回答
2

尝试Easy和一种尝试不带案例的方法,当..

Select 1 from dbo.EmailAddresses e 

    Inner Join Users u On e.UserID = u.UserID 
        Where LOWER(EmailAddress) = @EmailAddress                        
And  (   (@For = 1 and e.JurisdictionID IS NOT NULL)
        or ( @For = 2 and e.AccountID IS NOT NULL  ))
于 2012-09-04T13:21:23.457 回答