I have a table look like this:
ID brand version stock date
1 AA AAA 50 2019-11-11
1 AA AAA 52 2019-11-12
1 AA AAA 49 2019-11-13
...
2 BB BBB 30 2019-11-11
2 BB BBB 31 2019-11-12
2 BB BBB 31 2019-11-13
...
basically the date column is dynamic, because I extracted the last 14 days from now by using:
select id, brand, version, stock, date, DATEADD(DAY, -8, getdate()) as date_add
from myTable
where date > date_add
meaning that a week after the dates will be different than now, so my problem is how can I transpose this dynamic table? as I only know the trick to use "case..when", but in this case it doesn't work.
My desired output will be:
ID brand version 2019-11-11 2019-11-12 2019-11-13
1 AA AAA 50 52 49 ...
2 BB BBB 30 31 31 ...
I have searched the similar question, but there is only answer for using SQL Server for dynamic way of transpose.
How can I approach this? Thanks!