Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using alias within a calculation 1

Status
Not open for further replies.

NotSQL

Technical User
May 17, 2005
205
GB
Hi guys,

Im trying to use a alias with in a query but don’t seem to be getting the syntax correct.

I need to find the due date then use it to determine if its late or early.

Example

select z.DueDate, c.Name, case when z.DueDate < getdate() then 'Future' else 'ODue' end as 'ODUE'
from (Select CASE WHEN c.AckDate IS NULL
THEN c.RequiredDate ELSE c.AckDate END AS DueDate
From PURCHASE_ORDER_DETAIL c)z

Any help would be grateful
Regards
 
And where is your [c] alias in main query?
There is no one :)
You can't use aliases used in derived tables :)
BTW you don't need that derived table anyway :)
Code:
select DueDate, 
       Name,
       case when ISNULL(AckDate, RequiredDate) < getdate() 
                 THEN 'Future'
            else 'ODue' end as 'ODUE'
From PURCHASE_ORDER_DETAIL

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
try

Code:
select z.DueDate,  z.Name, case when z.DueDate < getdate() then 'Future' else 'ODue' end as 'ODUE'
from (Select [name], isnull(AckDate,RequiredDate) 
From  PURCHASE_ORDER_DETAIL )z
 
Thanks

but my duedate is base on:

when AckDate IS NULL i need the RequiredDate ELSE its the AckDate.

How is the Duedate calculated in your sql?

 
Check what ISNULL() function returns in BOL :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thanks bborissov,

I still need to calculate duedate though dont i? so would this be ok?

select ISNULL(AckDate, RequiredDate) as DueDate,
Name,
case when ISNULL(AckDate, RequiredDate) < getdate()
THEN 'Future'
else 'ODue' end as 'ODUE'
From PURCHASE_ORDER_DETAIL
 
Sure.
I will be OK.
I missed the part you need duedate in your main query.



Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top