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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Simple update query

Author  Topic 

Gregorys05
Starting Member

5 Posts

Posted - 2013-11-08 : 04:09:15
Hi all,
Im very new to writing sql scripts, i wrote the following code in access sql but when i copy it into SQL express 2012 i get an error saying
"Incorrect syntex near the keyword 'LEFT'"

Any ideas.


UPDATE dbo_TblMaster LEFT JOIN Tbl_RentalData ON dbo_TblMaster.Serial_Number = Tbl_RentalData.[Asset Serial Number] SET dbo_TblMaster.Current_Status = IIf([Tbl_RentalData].[Asset Serial Number]=[dbo_TblMaster].[Serial_Number],"On Circuit","Off Circuit"), dbo_TblMaster.Supplier_MPID = [Tbl_RentalData].[CustomerReference], dbo_TblMaster.Supplier_Group = [Tbl_RentalData].[Group_Supplier], dbo_TblMaster.Meter_Install_Date = [Tbl_RentalData].[Original Installation Date];


Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-08 : 04:36:31
[code]
UPDATE m
SET m.Current_Status = IIf(rd.[Asset Serial Number]=m.[Serial_Number],"On Circuit","Off Circuit"),
m.Supplier_MPID = COALESCE(rd.[CustomerReference],m.Supplier_MPID)
m.Supplier_Group = COALESCE(rd.[Group_Supplier], m.Supplier_Group)
m.Meter_Install_Date = COALESCE(rd.[Original Installation Date],m.Meter_Install_Date)
FROM dbo_TblMaster m
LEFT JOIN Tbl_RentalData rd
ON m.Serial_Number = rd.[Asset Serial Number]
[/code]

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

- Advertisement -