Solved

SQL:  Conditional Update

Posted on 2014-02-06
4
207 Views
Last Modified: 2014-02-11
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
Comment
Question by:mrherndon
4 Comments
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 250 total points
ID: 39840192
update frack set chillroomscan = dateadd(dd,1,chillroomscan)
where chillroomscan < racked
0
 

Author Comment

by:mrherndon
ID: 39840360
I see where you're going, but the script error returns column not found:  dd.  Any suggestions?
0
 
LVL 40

Expert Comment

by:Sharath
ID: 39840591
dd is not a column and it is to increment by day. Are you working in MS SQL or MYSQL?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 39841279
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now