How can I join this 2 queries?(A select query with join and An unpivot query)
Posted
by
MANG KANOR
on Stack Overflow
See other posts from Stack Overflow
or by MANG KANOR
Published on 2012-11-23T01:39:28Z
Indexed on
2012/11/23
4:59 UTC
Read the original article
Hit count: 198
Here are my two queries
SELECT EWND.Position,
NKey = CASE WHEN ISNULL(Translation.Name, '') = '' THEN EWND.Name
ELSE Translation.Name END, Unit = EW_N_DEF.Units
FROM EWND
INNER JOIN EW_N_DEF ON EW_N_DEF.Nutr_No = EWND.Nutr_No
LEFT JOIN Translation ON Translation.CodeMain = EWND.Nutr_no
WHERE Translation.CodeTrans = 1
ORDER BY EWND.Position
And this is the unpivot one
SELECT *
FROM
(SELECT N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27,N28,N29,N30,N31,N32,N33,N34
FROM EWNVal WHERE Code=6035) Test
UNPIVOT
(Value FOR NUTCODE IN
(N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27,N28,N29,N30,N31,N32,N33,N34)
)AS test
Both Queries put out same number of rows but not columns, Is it possible to join this two? I tried the union but it has problems that I cant solve
Thanks in advance!
© Stack Overflow or respective owner