[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

SQL: Conditional Update

Attached is a screenshot of a database table called FRACK.

I'm looking for help creating a SQL update statement which would compare timestamps in columns RACKED and CHILLROOMSCAN.  If the CHILLROOMSCAN is an earlier date than the RACKED date, I would like to increment the CHILLROOMSCAN value by 1 day, leaving the hour/min/sec AM/PM details unchanged.  

If the CHILLROOMSCAN value is the same date or later than the RACKED value, then no change should take place.

Can someone help?
frack.jpg
0
mrherndon
Asked:
mrherndon
2 Solutions
 
awking00Commented:
update frack set chillroomscan = dateadd(dd,1,chillroomscan)
where chillroomscan < racked
0
 
mrherndonAuthor Commented:
I see where you're going, but the script error returns column not found:  dd.  Any suggestions?
0
 
SharathData EngineerCommented:
dd is not a column and it is to increment by day. Are you working in MS SQL or MYSQL?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in ms sql server, it would by DAY and not DD:
update frack set chillroomscan = dateadd(day,1,chillroomscan)
where chillroomscan < racked 

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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