Forum Discussion
Need help with sql update query
Very much a newbie... Trying to update a field in one table based on a parameter from another table in the same database in SSMS. Could some one take a look at what I have come up with so far and lead me in the right direction? Thanks
Use [practice_acr]
go
update practice_acr.sb.site
set practice_acr.sb.site.customerpono2 = 'ST'
inner join practice.acr.sb.site.customerno = practice_acr.ar.customer.customerno
where practice_acr.ar.customer.lastinvoicedate > '1/1/2018 12:00:00PM'
go
- SnowMan55Bronze Contributor
bussk You may have the correct syntax, except... Notice that at the start of the INNER JOIN clause you have practice.acr.sb..., which apparently should be practice_acr.sb...
As you have a USE statement in the batch, the database prefixes (practice_acr.) are not needed, and are visual clutter.
And while 1/1/2018 is fortunately not ambiguous, if you will have to deal with the execution of queries in other countries, other dates might be ambiguous; e.g., 03/11/2018 could mean March 11 or could mean November 3. So a syntax of 2018-01-01 (yyyy-mm-dd) is preferred; IIRC, '2018-01-01T12:00:00' is the best.