SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Where by one column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

yoyosh
Starting Member

27 Posts

Posted - 01/30/2013 :  04:19:48  Show Profile  Reply with Quote
Why the following query is incorrect?

select (select top 1 date from pass_in_trip p where p.trip_no = t.trip_no) as date
from trip t
where date is not null

It says: Invalid column name 'date'.

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/30/2013 :  04:25:16  Show Profile  Reply with Quote
date is an alias created in same level so cant be used in where like that. so you need to tweak it like this

select *
from
(
select (select top 1 date from pass_in_trip p where p.trip_no = t.trip_no) as [date]
from trip t
)p
where [date] is not null


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

yoyosh
Starting Member

27 Posts

Posted - 01/30/2013 :  06:29:34  Show Profile  Reply with Quote
Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/30/2013 :  06:48:28  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000