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.
| 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_ccWhen ttl_data.cc then ttl_data.cc + '-' + ttl_data.ia + '-' + ttl_data.case_id +'-' + ttl_data.case_line + '-' + ttl_data.wcnELSE 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 commentFrom tp Inner JOIN ttl_data on LEFT(tp.trk_link,20) = ttl_data.case_id_ds + ttl_data.case_mstr + ttl_data.trk_seqinner Join prog_mess on LEFT(tp.trk_link,20) = prog_mess.case_id_ds + prog_mess.case_mstr + prog_mess.trk_seqLeft Join progress_message on progress_message.progress_m = prog_mess.pg_mess_id) as abcWHERE 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 |
|
|
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 17The multi-part identifier "tp.scn" could not be bound.Msg 4104, Level 16, State 1, Line 17The multi-part identifier "tp.action_cd" could not be bound.Msg 207, Level 16, State 1, Line 17Invalid column name 'ttype'.Msg 207, Level 16, State 1, Line 17Invalid column name 'ttype'.Msg 207, Level 16, State 1, Line 17Invalid column name 'title_nm'.Msg 4104, Level 16, State 1, Line 18The multi-part identifier "prog_mess.eff_dt" could not be bound. |
 |
|
|
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. |
 |
|
|
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. |
 |
|
|
|
|
|
|
|