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 2005 Forums
 Transact-SQL (2005)
 self update to a column

Author  Topic 

8022421
Starting Member

45 Posts

Posted - 2009-01-30 : 11:39:50
I have column called ACGT_key which holds a string value as '2008042518430643200007112021486300000000' , The first 8 characters include date and other 8 characters include the time and the next 8 characters include the date and gain the next 8 characters include the time. My task is to update this date & time which is previosuly there with the current date & time, I don't want to alter the other columns which is existing , I just want to update just system date and time without affecting the other columns,Please help me in this.

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-30 : 11:49:20
So you have a string that is a concatenation of two datetimes? Wow. Do you need to update both halves of the string to the current datetime or just the first half?

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-30 : 11:49:20
you want to replace this column value with current datetime?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2009-01-30 : 11:49:27
Which date and time do you want to update? First or second?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-30 : 11:50:13
quote:
Originally posted by visakh16

you want to replace this column value with current datetime?



We posted at the same time :D

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page

8022421
Starting Member

45 Posts

Posted - 2009-01-30 : 11:50:16
I want to update the both the half with the current date and time..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-30 : 11:55:48
quote:
Originally posted by Skorch

quote:
Originally posted by visakh16

you want to replace this column value with current datetime?



We posted at the same time :D

Some days you're the dog, and some days you're the fire hydrant.


wow! thts cool
Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-30 : 12:40:56
Assuming you just want to replace the first 16 characters of that string with the current datetime, this should work. It's very ugly though.

SELECT REPLACE(ACGT_key, SUBSTRING(ACGT_key,0,17),REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(22),GETDATE(),121),'-',''),':',''),'.',''),' ',''))
FROM YourTable

You should be able to convert this select into an update after verifying that this is the expected result.

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page

8022421
Starting Member

45 Posts

Posted - 2009-01-30 : 13:10:58
Thanks Skorch...Thats great,,,
Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-30 : 13:11:22
You're welcome.

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page
   

- Advertisement -