Friday, March 23, 2012

How to get the description ?

Hi,
I have a SQL that is working fine:

SELECT DISTINCT T1.ATCkod FROM ATC_tot T1
JOIN ATC_tot T2 ON T2.ATCkod = T1.ATCkod and T2.Typ_lakemedel LIKE '%' + @.Kod2 + '%'
JOIN ATC_tot T3 on T3.ATCkod = T1.ATCkod AND T3.Typ_lakemedel LIKE '%' + @.Kod3 + '%'
WHERE T1.Typ_lakemedel = @.Kod
Now I need to have a description together with the ATCkod, tablename ATC columnnameATCdesc. ATC_tot.ATCkod =ATC.ATCkod. I have tried Inner join without success. Any good suggestions ...?

Note that if you do not specify a JOIN type, INNER is the default. I prefer to specify the JOIN type for clarity.
Doesn't this work?

SELECTDISTINCT
T1.ATCkod,
ATC.ATCdesc
FROM
ATC_tot T1
INNER JOIN
ATC_tot T2 ON T2.ATCkod = T1.ATCkod and T2.Typ_lakemedel LIKE '%' + @.Kod2 + '%'
INNER JOIN
ATC_tot T3 on T3.ATCkod = T1.ATCkod AND T3.Typ_lakemedel LIKE '%' + @.Kod3 + '%'
INNER JOIN
ATCkod ATC ON T1.ATCkod = ATC.ATCkod
WHERE
T1.Typ_lakemedel = @.Kod

sql

No comments:

Post a Comment