Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update Query Help

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-01-15 : 04:31:34
hey Guys

Hope your well

Sorry for this basic question, but its really got me stumped

Aim - Update #account Last_Post_Date with the [LAST_POSTING_DATE] from the #501 table.

Currently My update inst working, But i think its because i haven't joined my #501 on to my #account via the FDMSaccountno


this is my query

select
Fdmsaccountno,
Parentid,
Last_Post_Date
into #account
from [Dim_Outlet]


Select
Fdmsaccountno,
[LAST_POSTING_DATE]
Into #501
FROM [FDMS].[dbo].[stg_LMPAB501]


I got my update as follows

--Update --
update #account
set Last_Post_Date = [LAST_POSTING_DATE]
from #501
where [LAST_POSTING_DATE] > Last_Post_Date


Looking for any help avaiable

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-01-15 : 04:34:01
It maybe

update #account
set Last_Post_Date = [LAST_POSTING_DATE]
from #501
where #501.FDMSAccountNo = #account.FDMSAccountNo

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-15 : 04:53:46
what if there are multiple values of [LAST_POSTING_DATE] in #501 which is > Last_Post_Date value in #account for the same accountno?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-01-15 : 05:01:11
HI visakh16


There isnt multiple [LAST_POSTING_DATE] .
Every Fdmsaccountno has one [LAST_POSTING_DATE]
Go to Top of Page
   

- Advertisement -