Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to make a new concatenated datecolumn?

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2010-10-22 : 05:53:57
hi all,
In my table, I have columns day,month,year as separarte fields, now I need to add a new column as date, which will the concatenation of those fields above. My table contains about 1000 records...So I want to get the date-values to new column and need to drop old ones one by one, so that only date-field is there with values?
And day,month,year are all int fields

I added the new field as date with datetime type...
What update query I need to perform for this?

Thanks in advance

sql-programmers
Posting Yak Master

190 Posts

Posted - 2010-10-22 : 06:18:07
Consider
D1 as day column
Y1 as year column
M1 as month column
and FinalD as datatime columns.

So your update will be,

Update table tblTemp set FinalD = convert(datatime, (convert(varchar,M1) + '/' + convert(varchar,D1) + '/' + convert(varchar,Y1)))

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2010-10-22 : 06:26:22
Thanks, it worked ....



quote:
Originally posted by sql-programmers

Consider
D1 as day column
Y1 as year column
M1 as month column
and FinalD as datatime columns.

So your update will be,

Update table tblTemp set FinalD = convert(datatime, (convert(varchar,M1) + '/' + convert(varchar,D1) + '/' + convert(varchar,Y1)))

SQL Server Programmers and Consultants
http://www.sql-programmers.com/

Go to Top of Page
   

- Advertisement -