Using Derived Column Results Again in Queries

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Don Miller (nospam_at_nospam.com)
Date: 07/28/04


Date: Wed, 28 Jul 2004 16:48:51 -0500

Is there any way to use a derived column elsewhere in a query (as in the
example below)? In my app I derive a column using a CASE statment and want
to use that result later on in the query to create another derived column
indicating an alarm situation. Thanks.

SELECT OrderID,
       DATEDIFF(dd, ShippedDate, GETDATE() ) AS DaysSinceShipped,
       DaysSinceShipped * 2 AS TwiceAsManyDaysSinceShipped
FROM Northwind.dbo.Orders
WHERE ShippedDate IS NOT NULL



Relevant Pages

  • Re: Using Derived Column Results Again in Queries
    ... Zach Wells wrote: ... >> to use that result later on in the query to create another derived column ... >> WHERE ShippedDate IS NOT NULL ...
    (microsoft.public.sqlserver.programming)
  • Re: How to calculate Last Friday of the Month ?
    ... yearnumber respectively, rest everything gets calculated by query. ... lst_dt column its a derived column from following derived table/inline view. ...
    (microsoft.public.sqlserver.programming)
  • Re: Using Derived Column Results Again in Queries - thanks
    ... In my app I derive a column using a CASE statment and want ... > to use that result later on in the query to create another derived column ... > WHERE ShippedDate IS NOT NULL ...
    (microsoft.public.sqlserver.programming)
  • Derived column names
    ... Anyone know how to use a variable to set a derived column ... prefer to do this DB-side rather than in the app. ... DECLARE @COL AS NVARCHAR ...
    (microsoft.public.sqlserver.programming)