Try to search your question here, if you can't find : Ask Any Question Now ?

How to make repeating custom expressions in SQL queries maintainable

HomeCategory: stackoverflowHow to make repeating custom expressions in SQL queries maintainable
Avatarpushpa asked 5 months ago

Imagine the following simple query, where I get a list of all users that were created within the last 3 days, the logic or example is not important

SELECT
    ...
    , DATEDIFF(DAY, U.DateCreated, GETUTCDATE())
    ...
FROM
    dbo.AspNetUsers U
WHERE
    DATEDIFF(DAY, U.DateCreated, GETUTCDATE()) < 3

I’ve repeated some code DATEDIFF(DAY, U.DateCreated, GETUTCDATE()) < 3 which, when I have much more complicated examples of the above I don’t want to maintain twice or however many times I need that logic.

How should one go about dealing with this with performance in mind?

Thanks

1 Answers
Best Answer
AvatarJyoti answered 5 months ago
Your Answer

19 + 17 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com