Solved

SQL Field Mass Update

Posted on 2013-01-07
3
270 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:
Scott Pletcher 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

773 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