开发者

Better way of writing this SQL WHERE Clause

开发者 https://www.devze.com 2023-01-25 12:30 出处:网络
I have something si开发者_StackOverflow中文版milar to the following WHERE clause in my SQL statement:

I have something si开发者_StackOverflow中文版milar to the following WHERE clause in my SQL statement:

AND (ipdp.UserID!=dbo.fn_userid(ipdp.ItemID) OR dbo.fn_userid(ipdp.ItemID) IS NULL)

However, I don't like how dbo.fn_userid function is being ran twice. How can I improve this line of code so that it only has to be ran once?

ipdp.UserID is always a Non-NULL Integer value

dbo.fn_userid can return a NULL or an Integer value

Cheers.


Try:

 AND ipdp.UserID != ISNULL(dbo.fn_userid(ipdp.ItemID), -1)
0

精彩评论

暂无评论...
验证码 换一张
取 消