-1

I need some help to solve this Problem. I have a SQL Server table that has a similar structure like this.

I Need to unpivot Article, Amount and Price. (Notice i don't have a Price 1)

enter image description here

user2210516
  • 613
  • 3
  • 15
  • 32

1 Answers1

1

Use cross apply:

select v.*
from t cross apply
     (values (t.id, t.article1, t.amount1, NULL),
             (t.id, t.article2, t.amount2, t.price2),
             (t.id, t.article3, t.amount3, t.price3),
             (t.id, t.article4, t.amount4, t.price4)
     ) v(id, article, amount, price)
where v.article is not null;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786