Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql... if then update

Posted on 2013-01-11
5
Medium Priority
?
297 Views
Last Modified: 2013-01-11
Hi Guys,

I am trying to say if [Clearing_Broker] = 'one'
then
run this update
	UPDATE dbo.DailyPositions_JEFF
	SET [Jeff_Multiplier] = 
	(SELECT dbo.MarketsDB.[JEFF_MULTIPLIER]
	FROM dbo.MarketsDB
	INNER JOIN dbo.AccountsDB
	ON dbo.DailyPositions_JEFF.Account_ID = dbo.AccountsDB.Account_ID
	WHERE [JEFF_SYMBOL]= dbo.DailyPositions_JEFF.[Product]
	AND [Clearing_Broker] = 'one'
	)

Open in new window


else

run this update
	UPDATE dbo.DailyPositions_JEFF
	SET [Jeff_Multiplier] = 
	(SELECT dbo.MarketsDB.[UBS_MULTIPLIER]
	FROM dbo.MarketsDB
	INNER JOIN dbo.AccountsDB
	ON dbo.DailyPositions_JEFF.Account_ID = dbo.AccountsDB.Account_ID
	WHERE [UBS_SYMBOL]= dbo.DailyPositions_JEFF.[Product]
	AND [Clearing_Broker] = 'two'
	)

Open in new window



can anyone help me combine this into a if then run update 1, else run update 2

thanks!!
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
  • 3
5 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 38767964
UPDATE dp

SET [Jeff_Multiplier] = case when [Clearing_Broker] = 'one' then mdb2.[JEFF_MULTIPLIER]
else mdb.[UBS_MULTIPLIER] end

from

 dbo.DailyPositions_JEFF dp
join dbo.MarketsDB mdb on mdb.[UBS_SYMBOL]= dp.[Product]
join dbo.MarketsDB mdb2 on mdb2.[JEFF_SYMBOL]= dp.[Product]
join dbo.AccountsDB adb on dp.Account_ID = adb.Account_ID
0
 

Author Comment

by:solarissf
ID: 38767985
sorry, I dont understand this.  Do I paste the whole thing in?  when I do I get errors on the inner join
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 38767988
try this
UPDATE dbo.DailyPositions_JEFF
	SET [Jeff_Multiplier] = 
	(SELECT 
		case 
			when [Clearing_Broker] = 'one' then 
				dbo.MarketsDB.[JEFF_MULTIPLIER]
			when [Clearing_Broker] = 'two'then	
				dbo.MarketsDB.[UBS_MULTIPLIER]
		end
	FROM dbo.MarketsDB
	INNER JOIN dbo.AccountsDB
	ON dbo.DailyPositions_JEFF.Account_ID = dbo.AccountsDB.Account_ID
	WHERE ([JEFF_SYMBOL]= dbo.DailyPositions_JEFF.[Product]
			AND [Clearing_Broker] = 'one')
	OR ([UBS_SYMBOL]= dbo.DailyPositions_JEFF.[Product]
			AND [Clearing_Broker] = 'two')
	)

Open in new window

0
 

Author Comment

by:solarissf
ID: 38768023
AWESOME... WORKS

THANKS SO MUCH
0
 

Author Comment

by:solarissf
ID: 38768842
Okay, last one.  And if I need to put in a new post I will.  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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

704 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