Thursday, March 22, 2012

Can unpivot help me here?

HI, I have a source that looks like this:

Col1 Code1 Amt1 Col<n>.....Code2 Amt2....
ABC XY 10 FR 345

What I would like to have is this:

Col1 Code Amt Col<n> ...
ABC XY 10
ABC FR 345

I know I could achieve this by using SQL and UNION ALL:
SELECT Col1, Code1 as Code, Amt1 as Amt, Col<n>...
FROM <mySource>
UNION ALL
SELECT Col1, Code2 as Code, Amt2 as Amt, Col<n>...
FROM <mySource>

But I was wondering if the built-in unpivot transform could do the job here.

Thank you
Ccote

No, it won't. UNPIVOT would help if your data looked like this:

Col1 Col<n> XY_amt FR_amt

ABC .... 10 345

Sorry!

-Jamie

|||

All right! I think that I will stick with the good old SQL ! :-)

Thanks Jamie!

No comments:

Post a Comment