SAS max in SQL Server -


trying reengineer sas code in sql server. code has proc-sql file following statement.

   sum(case when max(t1,t2) = 0 , transac='d'  sales else 0 end)/sum(sales) 

i tried convert sql using below, apparently incorrect. hoping here can point out right approach.

 sum(case when (select max(tval)  values(t1,t2) tval) = 0 , transac = 'd' sales else 0)/nullif(sum(sales),0) 

also tried:

  sum(case when (t1 > t2 , t1 = 0 or t2 > t1 , t2 = 0) , transac ='d' sales else 0 end)/nullif(sum(sales),0) 

however, not replicate sas result using approach.

any appreciated.

thanks, b

assuming t1 , t2 columns...

you can use cte

with cte1 (select max(t1), max(t2) footable),  cte2 (select  case when sum(t1 + t2) = 0 , max(footable.transac) = 'd' sales else 0 end foocolumn cte1, footable)  select sum(foocolumn) / sum(table.sales) cte2, table 

i think might work... think max(footable.transac) might mess up. able provide small sample data of you're working with?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -