New answers tagged

0

This is what I intended to say in my comment: select ctr_id, mth, cumulative_pmt_amt , coalesce(cumulative_amt, 0) as cumulative_amt , coalesce(cumulative_amt, 0) - cumulative_pmt_amt as balance from ( select ctr_id, mth , sum(pmt_amt) over (partition by ctr_id order by mth) as cumulative_pmt_amt ...


5

SELECT DISTINCT a.col_a ,b.col_c FROM tab_a a outer apply (select top 1 b.col_c from tab_b b where ((a.col_a = b.col_a AND b.col_b = 'blabla1' ) or (a.col_a = b.col_a AND b.col_b = 'blabla2') or (a.col_a = b.col_a AND ...


0

SELECT DISTINCT a.col_a ,b1.col_c FROM tab_a a LEFT JOIN tab_b b1 ON a.col_a = b1.col_a AND b1.col_b IN ('blabla1','blabla2','blabla3'); 1 join as requested ^^ edited to a somewhat more elegant style using IN ( .. )


1

If you want or have that 3 descriptions static, you can do the following: Create a temp table or variable table Insert the values in the temp or variable table but in form of column https://stackoverflow.com/questions/15745042/efficiently-convert-rows-to-columns-in-sql-server Write the script in your answer but delete those 3 LEFT JOIN and just do a CROSS ...


Top 50 recent answers are included