Groups | Blog | Home
all groups > sql server programming > august 2004 >

sql server programming : Update with dates


Aleks
8/6/2004 11:41:39 PM
This could be an easy one

I have a table with 3 fields as follows:

1) Userid - int (This is the key identity field)
2) I94Date - varchar
3) I94DateD - smalldatetime

I SEE TWO OPTIONS FOR WHAT I NEED: OPTION # 1

I need to update the I94Date for all the table, so that for record # 1 the
I94DateD is copied to field I94Date, the trick here is to instead of copying
the field as it is: 2003-08-02 00:00:00 it needs to be converted to:
08/02/2004

then go to the next record and do the same for all the table.

OR : OPTION # 2

second option is to re-format all values in the I94Date column, which are
displayed as: Aug 2 2003 12:00AM
and re-format the values to 08/02/2004

Whichever is easier. Help is greately appreciated.

A

Steve Kass
8/7/2004 1:21:39 AM
Aleks,

There is usually no reason to keep the same information in two columns of
a table. If for some reason it isn't practical to select convert(char(10),
I94DateD, 101) whenever you need to retrieve a date in MM/DD/YYYY format,
you could make I94Date a calculated column:

create table T (
Userid int,
I94DateD smalldatetime,
I94Date as convert(char(10), I94DateD, 101)
)

You could update the entire table with

update T set
I94Date = convert(char(10), I94DateD, 101)

but I can't really see where that would be a good solution.

Steve Kass
Drew University

[quoted text, click to view]

Aleks
8/7/2004 8:39:16 PM
Thanks a lot, I simply did this: UPDATE users set
I94Date = convert(char(10), I94DateD, 101)


A


[quoted text, click to view]

AddThis Social Bookmark Button