vb.net - How to achieve this model -
i have table this

i trying achieve table this: 
this query.
select name,token , sum(qty) [qty],sum(amount)from #temp group token,name tried this..
select * (select name, qty,amt, token #temp1 ) d pivot(sum(amt) token in ([10],[20],[100],[40],[5])) p it not working though. appreciated.
i think can achieve following statement:
select [name], sum((case when [token] = 10 [qty] else 0 end)) token_10_qty, sum((case when [token] = 10 [amt] else 0 end)) token_10_amt, sum((case when [token] = 50 [qty] else 0 end)) token_50_qty, sum((case when [token] = 50 [amt] else 0 end)) token_50_amt, sum((case when [token] = 100 [qty] else 0 end)) token_100_qty, sum((case when [token] = 100 [amt] else 0 end)) token_100_amt #temp1 group [name] assuming columns qty , amt not null. hope way.
Comments
Post a Comment