Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Field Mass Update

Posted on 2013-01-07
3
Medium Priority
?
278 Views
Last Modified: 2013-01-16
SELECT     custno, ldate, custstat
FROM         arcust

"ldate" is last date of sale dates formatted like "6/6/2007 12:00:00 AM"  The time is the same for all the dates.

"custstat" date is a "I" or "A".  This field is for active or in-active.

I am looking to make all customer with a last date of sale of 12/31/11 or older have a status of "I"
0
Comment
Question by:jasonspopma
  • 2
3 Comments
 
LVL 23

Assisted Solution

by:Steve Wales
Steve Wales earned 500 total points
ID: 38752005
Assuming that ldate is a char field, this should do it:

update arcust
set custstat = 'I'
where convert(datetime, ldate, 101) <= convert(datetime, '20111231')
0
 
LVL 23

Expert Comment

by:Steve Wales
ID: 38752035
As long as the time portion of every value in your column is represented as midnight, the above should do the trick.
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 38756184
"ldate" *displays* like that in the SELECT, but since that's the default for a datetime, it's likely (hopefully) a datetime data type.

If so, this is best.  And even if it's varchar this will work (as long as all values are valid datetimes):


UPDATE dbo.arcust
SET custstat = 'I'
WHERE
    ldate < CAST('20120101' AS datetime)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

916 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