Solved

SQL Field Mass Update

Posted on 2013-01-07
3
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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
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.

735 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