Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Invalid column name

Author  Topic 

rsvore
Starting Member

15 Posts

Posted - 2012-04-03 : 13:26:59
I've found this type of solution on the net for invalid column name to wrap the statement in a select * from (Select ...)and tried to apply it to my statement below but I get several errors because of the inner joins. I'm trying to get trackno to work in the where clause.

Select * from(
SELECT Distinct tp.surname_nm, tp.given_nm, tp.scn, ttl_data.case_id_ds + ttl_data.case_mstr + ttl_data.trk_seq AS track,
CASE ttl_data.p_cc
When ttl_data.cc then ttl_data.cc + '-' + ttl_data.ia + '-' + ttl_data.case_id +'-' + ttl_data.case_line + '-' + ttl_data.wcn
ELSE ttl_data.cc + '-' + ttl_data.ia + '-' + ttl_data.case_id + ttl_data.case_line +' -'+ ttl_data.wcn + '(' + ttl_data.p_cc +')' END as trackno,
prog_mess.case_id_ds,prog_mess.case_mstr,prog_mess.trk_seq,prog_mess.trk_ln_seq,prog_mess.eff_dt,prog_mess.prior_dt,prog_mess.last_dt,prog_mess.pub_cmnt, RTRIM(progress_message.title_nm) + ' (' + RTRIM(prog_mess.pg_mess_id) + ')' as comment
From tp
Inner JOIN ttl_data on LEFT(tp.trk_link,20) = ttl_data.case_id_ds + ttl_data.case_mstr + ttl_data.trk_seq
inner Join prog_mess on LEFT(tp.trk_link,20) = prog_mess.case_id_ds + prog_mess.case_mstr + prog_mess.trk_seq
Left Join progress_message on progress_message.progress_m = prog_mess.pg_mess_id) as abc
WHERE tp.scn = @scn and tp.action_cd <> 'D' AND ttype in('IMS','CLO') and title_nm is not null and trackno = 'AT-B-OEA-001-0253'
Order by prog_mess.eff_dt Desc

X002548
Not Just a Number

15586 Posts

Posted - 2012-04-03 : 14:10:34
ummm..do you think it MIGHT be helpful if you post the error?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

rsvore
Starting Member

15 Posts

Posted - 2012-04-03 : 16:02:26
Your right forgot the erro rmessages:
Msg 4104, Level 16, State 1, Line 17
The multi-part identifier "tp.scn" could not be bound.
Msg 4104, Level 16, State 1, Line 17
The multi-part identifier "tp.action_cd" could not be bound.
Msg 207, Level 16, State 1, Line 17
Invalid column name 'ttype'.
Msg 207, Level 16, State 1, Line 17
Invalid column name 'ttype'.
Msg 207, Level 16, State 1, Line 17
Invalid column name 'title_nm'.
Msg 4104, Level 16, State 1, Line 18
The multi-part identifier "prog_mess.eff_dt" could not be bound.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-04-03 : 17:13:27
The main issue is that your derived table ABC contains all the columns. But, in the where clause you are referncing the base tables and not the derived table alias and you are referncing coluns that aren't even in the derived table.

Bad table refernce: tp.scn needs to be ABC.scn, etc..
Non Existant columns: title_nm and ttype.
Go to Top of Page

rsvore
Starting Member

15 Posts

Posted - 2012-04-03 : 20:19:58
Thanks for your help. I got it working by reworking what I had written.
Go to Top of Page
   

- Advertisement -