Solved

sql, if then else in stored procedure

Posted on 2013-01-14
3
356 Views
Last Modified: 2013-01-14
Hi All,

I'm trying to do the below and not so great at sql.  Can anyone help me with the following statement?

.  This will be in a stored procedure
same concept as if then else...  but i dont think it can be a case

This is my original.

UPDATE dbo.DailyPositions_JEFF
SET [P&L Settlement]= (((ISNULL([Delta Settlement],0)*[Value 1Point])*[Local Rate])*[Qty_Net])

Open in new window


I want to say...
If [Value 1Point] = 0.9999
Then
do this
SET [p&L Settlement] =
[delta settlement] *
(1/[tick_size]) *[tick_value]
*
[local rate]

else.... do this

SET [P&L Settlement]= (((ISNULL([Delta Settlement],0)*[Value 1Point])*[Local Rate])*[Qty_Net])



thanks for all the help
0
Comment
Question by:solarissf
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 38774138
Case will still work, here

UPDATE dbo.DailyPositions_JEFF
SET [P&L Settlement] =
	case
		when [Value 1Point] = 0.9999 then
			(((ISNULL([Delta Settlement],0)*[Value 1Point])*[Local Rate])*[Qty_Net])
		else
			[delta settlement] * (1/[tick_size]) *[tick_value]*[local rate]
	end

Open in new window

0
 

Author Comment

by:solarissf
ID: 38774145
ahha.... I didnt know that... kinda looks like a iF ELSE anyway.
looks that this will work... thanks!!!  I'll try it out
0
 

Author Comment

by:solarissf
ID: 38774532
worked... thank you!!!

another question in terms of performance and speed.

which is faster..
1.   to use the case ... else
or
2.  have the stored procedure call a scalar function
scalar function using pulled in paramaters will a true if else
?
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question