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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDate not working

Status
Not open for further replies.

williadn48

Programmer
Oct 27, 2006
29
US
I am trying to update a field with itself plus another field in SQL Query Analyzer.

Update ECMTTConversion
set EntryDate = EntryDate + '' + Starttime
go

EntryDate has only a date in it. StartTime has only a time in it. I need to concatenate them into one field.

I keep getting:
String or binary data would be truncated.
The statement has been terminated.
 
You are working with varchar columns. YOu need to make EntryDate wide enough to hold both values concatenated (at the moment, it is not).

You should really store this in a datetime column though. If you post sample data we can help you accomplish this.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
If EntryDate and StartTime are both DateTime data types, then....

Code:
Update ECMTTConversion
set EntryDate = EntryDate + Starttime

Don't run this code twice because you'll mess up your data.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
What does your time data look like? Do you need to add ':'?
try this if you do?

Code:
[COLOR=blue]DECLARE[/color] @DateTime [COLOR=#FF00FF]datetime[/color]
       ,@date [COLOR=blue]char[/color](8)
       ,@time [COLOR=blue]Char[/color](6)
[COLOR=blue]SET[/color] @Date=[COLOR=red]'20070622'[/color]
[COLOR=blue]SET[/color] @Time=[COLOR=red]'094400'[/color]
[COLOR=blue]SELECT[/color] @DateTime=[COLOR=#FF00FF]CONVERT[/color]([COLOR=#FF00FF]datetime[/color], @Date + [COLOR=red]' '[/color] + [COLOR=#FF00FF]STUFF[/color]([COLOR=#FF00FF]STUFF[/color](@Time, 3, 0, [COLOR=red]':'[/color]), 6, 0, [COLOR=red]':'[/color]))
[COLOR=blue]SELECT[/color] @DateTime

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top