Referencing a calculated column in the where clause SQL

后端 未结 2 1273
滥情空心
滥情空心 2020-12-17 14:35

This line of code is a snippet from my select statement.

frdFreedays - DateDiff(dd,conReceiptToStock,GetDate()) As FreeDaysRemaining

Below

2条回答
  •  时光说笑
    2020-12-17 15:08

    In addition to Aaron's answer, you could use a common table expression:

    ;with cte_FreeDaysRemaining as
        (
            select
                frdFreedays - DateDiff(dd,conReceiptToStock,GetDate()) As FreeDaysRemaining
                --, more columns
            from yourtable
        )
        select
            FreeDaysRemaining
            --, more columns
        from cte_FreeDaysRemaining
        where FreeDaysRemaining <= @intFreeDays
    

提交回复
热议问题