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
 how can I link two tables using a concat function?

Author  Topic 

avalle
Starting Member

3 Posts

Posted - 2010-07-30 : 08:17:29
How can I link the values from two tables using a concat value as common reference between them?

This is the rough idea of what I want to do:

select t1.column_X, t2.column_Y from table1 t1, table2 t2
when concat(column_A,column_B,column_C) from table 1 = concat (column_A, c_b, column_C) from table 2

Hope guys you have the answer pto this question

Angel V.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-07-30 : 08:21:10
u want like this
select t1.column_X, t2.column_Y from table1 t1
join table2 t2 on t1.column_A = t2.column_A
and t1.column_B = t2.column_B
and t1.column_C = t2.column_C
Go to Top of Page

avalle
Starting Member

3 Posts

Posted - 2010-07-30 : 08:55:47
Many thanks for your answer,

Actually my SQL its more complex it looks like:


select a.DMDUNIT, a.DMDGROUP, a.LOC, a.FCSTDATE, a.STARTDATE, BASEFCST+NONBASEFCST FCST, h.qty, round(min(lag)/4.3,0) Monthly_Lag, lag Weekly_Lag

from histfcst a join hist h on a.dmdunit= h.dmdunit and a.loc = h.loc and a.startdate = h.startdate

where a.dmdunit= '5046' and a.scen=0 and a.loc <> 'USA' and a.dur=10 and a.dmdgroup='SALES'and a.startdate BETWEEN '01-jan-10' and '30-jun-10' and lag between '7' and '10'

group by a.DMDUNIT, a.DMDGROUP, a.LOC, a.FCSTDATE, a.STARTDATE, BASEFCST+NONBASEFCST, lag

Now the expression group by is sending me error messege. Do u have any clue how can I do it?




Angel V.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-07-30 : 08:58:44
i think u have miss the h.qty in the group by clause........

r can u post the error msg......
Go to Top of Page

avalle
Starting Member

3 Posts

Posted - 2010-07-30 : 09:32:44
I have aggregated h.qty but same error happen, it is as follows

Error -2147217900 - ORA-00936: missing expression

Angel V.
Go to Top of Page
   

- Advertisement -