How can I achieve the second picture using T-Sql language deriving from the first picture which is a database table.
Encircled w/ red will be becoming rows and there values will be put on the corresponding date from the slver_date
and that slver_date header which is highlighted w/ yellow will become columns containing the date.
The slvr_date values per item are the same count, so I could say that it is not dynamic.
and also the mapping is as follows:
oh_qty = starting onhand
firm_po = Firm Purchase Order
act_demand = firm_demand
tot_plan_trans_out = Planned Transfer Out
foh_ss = FOH-SS
ss_qrt = Safety Stock Qty
planned_purch = Planned Purchase
Expected Output
Someone told me to use Pivot, but I don't have any experience using it.
1条答案
按热度按时间ufj5ltwl1#
Here's a basic example of what pivot + unpivot combo might look like:
@dates_pivot will contains the unique "pivoted" dates, which goes to the pivot operator
@dates is similar, but also contains the alias for the headers if one wants those
Then we build dynamic sql which first unpivots columns a,b,c,d into value and finally pivots it back.
I couldn't get the colors working, but you should be able to figure out the rest