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
 General SQL Server Forums
 New to SQL Server Programming
 optimize help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pnpsql
Posting Yak Master

India
241 Posts

Posted - 07/25/2012 :  23:04:12  Show Profile  Reply with Quote

i have a table like
TBL_PARAM

PARAMETER_NAME VALUE
NEW1 10
NEW2 20
NEW3 30

and i need to use value like below

DECLARE @NEW1 NUMERIC(10), @NEW2 NUMERIC(10) , @NEW3 NUMERIC(10)

SELECT @NEW1 = VALUE FROM
TBL_PARAM where PARAMETER_NAME = 'NEW1'

SELECT @NEW2 = VALUE FROM
TBL_PARAM where PARAMETER_NAME = 'NEW2'

SELECT @NEW3 = VALUE FROM
TBL_PARAM where PARAMETER_NAME = 'NEW3'


and use the values for some calculation.


please suggest how can it be in one atatement and be optimize.


challenge everything

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 07/26/2012 :  00:19:02  Show Profile  Reply with Quote

DECLARE @NEW1 NUMERIC(10), @NEW2 NUMERIC(10) , @NEW3 NUMERIC(10)

SELECT @NEW1 = MAX(CASE WHEN PARAMETER_NAME = 'NEW1' THEN VALUE END),
@NEW2 = MAX(CASE WHEN PARAMETER_NAME = 'NEW2' THEN VALUE END),
@NEW3 = MAX(CASE WHEN PARAMETER_NAME = 'NEW3' THEN VALUE END) 
FROM TBL_PARAM 
where PARAMETER_NAME IN ('NEW1','NEW2','NEW3')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.03 seconds. Powered By: Snitz Forums 2000