Hello!
I got this code that fetches info from two tables, i want to join one more table to get the name of the partno (article name) this info I would get from table L62T1.partdsc1.How could i add one more join to get this info in the end result?
DECLARE @Date DATE = @('Ange datum:', #DATE)
Select partno, fmha, frack, fhorcoor, fvercoor, apgrp as plockstation, count(l16lcode) as "_Antal_Rader", datreg
FROM L16T3 L1
LEFT JOIN L30T1 L3 ON L1.fmha = L3.mha AND L1.frack = L3.rack AND L1.fhorcoor = L3.horcoor AND L1.fvercoor = L3.vercoor
Where l16lcode =4 AND apgrp <>'' AND datreg > = @Date
and datreg < DATEADD(dd, 1, @Date)
GROUP BY partno, fmha, frack, fhorcoor, fvercoor, apgrp, datreg
order by datreg desc
hi
i have formatted your code
but your question is not making any sense
DECLARE @Date DATE = @('Ange datum:', #DATE)
SELECT
partno
, fmha
, frack
, fhorcoor
, fvercoor
, apgrp as plockstation
, count(l16lcode) as "_Antal_Rader"
, datreg
FROM
L16T3 L1
LEFT JOIN
L30T1 L3
ON L1.fmha = L3.mha
AND
L1.frack = L3.rack
AND
L1.fhorcoor = L3.horcoor
AND
L1.fvercoor = L3.vercoor
WHERE
l16lcode =4
AND
apgrp <>''
AND
datreg > = @Date
AND
datreg < DATEADD(dd, 1, @Date)
GROUP BY
partno, fmha, frack, fhorcoor, fvercoor, apgrp, datreg
ORDER BY
datreg desc
I basically just want to add info from one more table into this code...I guess that I have to add one more join, but I dont get it to work without errors
Error message: Error when executing Sql
The multi-part identifier "L16T3.shortl62" could not be bound.
Ambiguous column name 'partno'.
Ambiguous column name 'partno'.
ErrorNo: 4104
--> Error on line: 9
DECLARE @Date DATE = @('Ange datum:', #DATE)
SELECT
partno
, fmha
, frack
, fhorcoor
, fvercoor
, apgrp as plockstation
, count(l16lcode) as "_Antal_Rader"
, datreg
FROM
L16T3 L1
LEFT JOIN
L30T1 L3
ON L1.fmha = L3.mha
AND
L1.frack = L3.rack
AND
L1.fhorcoor = L3.horcoor
AND
L1.fvercoor = L3.vercoor
JOIN L62T1 on L16T3.shortl62 = L62T1.shortl62
WHERE
l16lcode =4
AND
apgrp <>''
AND
datreg > = @Date
AND
datreg < DATEADD(dd, 1, @Date)
GROUP BY
partno, fmha, frack, fhorcoor, fvercoor, apgrp, datreg
ORDER BY
datreg desc