Solved

SQL Field Mass Update

Posted on 2013-01-07
3
263 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 22

Assisted Solution

by:Steve Wales
Steve Wales earned 125 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 22

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 69

Accepted Solution

by:
ScottPletcher earned 125 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
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.
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.

708 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

15 Experts available now in Live!

Get 1:1 Help Now