Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

sql... if then update

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
solarissf
Asked:
solarissf
  • 3
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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
 
solarissfAuthor Commented:
sorry, I dont understand this.  Do I paste the whole thing in?  when I do I get errors on the inner join
0
 
Ephraim WangoyaCommented:
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
 
solarissfAuthor Commented:
AWESOME... WORKS

THANKS SO MUCH
0
 
solarissfAuthor Commented:
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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now