Solved

sql... if then update

Posted on 2013-01-11
5
287 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
  • 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:
ewangoya earned 500 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell and sql server - alerting 7 77
Changing multiple SQL login passwords 9 31
AWE-based memory on 32-bit servers 1 23
Upgrading SQL Server Management Tools 7 36
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now