Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update only the date portion

Status
Not open for further replies.

password99

Technical User
Jul 19, 2002
122
US
i need to update the date portion (of datetime column) equal to date portion (of datetime column) of another column in the same table. How can i do that using SQL?
 
are you saying that there are time portions that you want to preserve the values of?



rudy
SQL Consulting
 
I think you are saying that you want to keep the time of day from the 1st column and replace only the date portion with the date portion of the 2nd column.
Code:
[Blue]DECLARE[/Blue] @dt1 [Blue]datetime[/Blue]
[Blue]DECLARE[/Blue] @dt2 [Blue]datetime[/Blue]
[Blue]SET[/Blue] @dt1[Gray]=[/Gray][red]'2004-08-01 8:00'[/red]
[Blue]SET[/Blue] @dt2[Gray]=[/Gray][red]'6/20/2004'[/red]
[Blue]SET[/Blue] @dt1[Gray]=[/Gray]@dt1[Gray]+[/Gray][Fuchsia]DateDiff[/Fuchsia][Gray]([/Gray]dd[Gray],[/Gray]@dt1[Gray],[/Gray]@dt2[Gray])[/Gray]
[Blue]SELECT[/Blue] @dt1
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Yes, I need to preserve the values of time portion.

Is it possible to do it with one update sql statement?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top