Solved

SQL:  Conditional Update

Posted on 2014-02-06
4
215 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 32

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

770 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