Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

sql, if then else in stored procedure

Posted on 2013-01-14
3
359 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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