Link to home
Start Free TrialLog in
Avatar of Stephen Forero
Stephen ForeroFlag for United States of America

asked on

updating sql table where other tables match

hi guys,

I have the following statement:

This creates a new table putting together pieces of 2 tables where 2 conditions exist.

Now I that the table exists... the second time I run this I just want to update the values.
Can someone please help me change this query from a create new table... to update the existing table.

Appreciate it
thanks


SELECT 
	dbo.PositionsDB.Account_ID, dbo.PositionsDB.Position_ID, dbo.AccountsDB.Account_Number, 
	dbo.AccountsDB.Account_Description,	dbo.PositionsDB.COB_Date, dbo.PositionsDB.Qty_Net, 
	dbo.PositionsDB.Exchange, dbo.PositionsDB.Product, dbo.PositionsDB.Contract_Date, 
	dbo.PositionsDB.Option_Type, dbo.PositionsDB.Strike,
	dbo.PositionsDB.Settlement_Price
INTO dbo.DailyPositions_JEFF
FROM dbo.PositionsDB
INNER JOIN dbo.AccountsDB
ON dbo.PositionsDB.Account_ID = dbo.AccountsDB.Account_ID
WHERE dbo.AccountsDB.Client_ID = '418bb7b8-0180-4a5a-99f6-ce52e60e694f'
AND [COB_Date] = '20121219'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Kroll
David Kroll
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stephen Forero

ASKER

as I'm am completed new to this... the section where you have
--update statements here

Can you show me 1 example of updating 1 column with my inner join statements

I'm stuck there as well

thanks soo much
Avatar of Guy Hengel [angelIII / a3]
update or delete + insert the rows?
UPDATE dbo.DailyPositions_JEFF
SET
Settlement_Price = 0
FROM dbo.DailyPositions_JEFF
INNER JOIN dbo.AccountsDB
ON dbo.DailyPositions_JEFF.Account_ID = dbo.AccountsDB.Account_ID
ANDdbo.AccountsDB.Client_ID = '418bb7b8-0180-4a5a-99f6-ce52e60e694f'
AND [COB_Date] = '20121219'
i tried this... still not working... at least for the 1 column

	UPDATE dbo.DailyPositions_JEFF
	SET
	Settlement_Price = dbo.PositionsDB.Settlement_Price
	FROM dbo.DailyPositions_JEFF
	INNER JOIN dbo.AccountsDB 
	ON dbo.DailyPositions_JEFF.Account_ID = dbo.AccountsDB.Account_ID 

Open in new window

UPDATE dbo.DailyPositions_JEFF
      SET
      Settlement_Price = dbo.PositionsDB.Settlement_Price
      FROM dbo.DailyPositions_JEFF
      INNER JOIN dbo.PositionsDB
      ON dbo.DailyPositions_JEFF.Account_ID = dbo.PositionsDB.Account_ID
i'm losing my mind here.

I'm not sure if I found source or not.

Lets assume that the table columns are there but there is not data in dbo.DailyPositions_JEFF.

I am trying to populate these columns
      dbo.PositionsDB.Account_ID, dbo.PositionsDB.Position_ID,      dbo.AccountsDB.Account_Number,
      dbo.AccountsDB.Account_Description,      dbo.PositionsDB.COB_Date, dbo.PositionsDB.Qty_Net,
      dbo.PositionsDB.Exchange, dbo.PositionsDB.Product, dbo.PositionsDB.Contract_Date,
      dbo.PositionsDB.Option_Type, dbo.PositionsDB.Strike,
      dbo.PositionsDB.Settlement_Price


.  So using your examples I just have to UPdate the columns.  This is the part I'm stuck on .
to make things a bit more confusing... and maybe the source of the problem
Account_ID is a unique identifier from AccountsDB
and Position_ID is a unique identifier from PositionsDB

is this why your update statement is not working... am I supposed to be updating all of them a tthe same time instead of each column?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks , i'll check it out
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
added to solution