Solved

sql, if then else in stored procedure

Posted on 2013-01-14
3
365 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
[X]
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
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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