SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Parameters SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Asnatyx
Starting Member

1 Posts

Posted - 05/24/2013 :  08:56:02  Show Profile  Reply with Quote

hello

how can i work with parameters, working with case, sum etc... instructions?
For example i have these lines that select some values, these values i want to store in a parameter because i want to SUM those fields after.... how is the better way to do this?


      CASE WHEN SUM(CASE WHEN A.TYPE_MOV = 1 THEN A.VALUE_MOV * -1 ELSE A.VALUE_MOV END) > 0 THEN SUM(CASE WHEN A.TYPE_MOV = 1 THEN A.VALOR_MOV * -1 ELSE A.VALUE_MOV END) ELSE 0 END AS VALUE_RECEIVE,
CASE WHEN SUM(CASE WHEN A.TYPE_MOV = 1 THEN A.VALUE_MOV * -1 ELSE A.VALUE_MOV END) < 0 THEN SUM(CASE WHEN A.TYPE_MOV = 1 THEN A.VALUE_MOV * -1 ELSE A.VALUE_MOV END) ELSE 0 END AS VALOR_PAY,


----z-----

bandi
Flowing Fount of Yak Knowledge

India
2208 Posts

Posted - 05/24/2013 :  09:13:58  Show Profile  Reply with Quote
--Try like this...

SELECT CASE WHEN VALOR_PAY1 WHEN >0 THEN VALUE_MOV1 ELSE 0 END VALUE_RECEIVE
	,CASE WHEN VALOR_PAY1 <0 THEN VALOR_PAY1 ELSE 0 END VALOR_PAY
FROM  (SELECT SUM(CASE WHEN A.TYPE_MOV = 1 THEN A.VALUE_MOV * -1 ELSE A.VALUE_MOV END) VALOR_PAY1
			,SUM(CASE WHEN A.TYPE_MOV = 1 THEN A.VALOR_MOV * -1 ELSE A.VALUE_MOV END) VALUE_MOV1
		FROM TableNAme 
	  ) Temp


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000