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

how to convert ':00:00.000' to varchar

Status
Not open for further replies.

saravananpk

Programmer
Jul 20, 2002
8
IN
i tried to convert ':00:00.000' to varchar using
convert and cast.

convert(varchar(20),':00:00.000')

but iam getting the following error.

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '00'.

how to convert that string to varchar.
 
sorry, the problem was not due to that.

i tried to add the time part to datetime.

set @datetimevar = @distributiondatetime + @hour

in this hour is in the format 'hh:mm:ss' but of type varchar in the table.

when i tried to add this varchar to datetime iam getting that error.

 
hi Terry L. Broadbent,

even then iam getting the same error

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '00'.

the problem is iam adding '02:02:10.000' (sample time) to datetime

datetimevar & distributiondatetime are datetime

set @datetimevar = @distributiondatetime + ' ' + @hour


 
You'll need to post more of the script and tell the data type of each variable. I can't guess what you are doing. I just ran the following without error.

Declare
@datetimevar datetime,
@distributiondatetime varchar(10),
@hour varchar(12)
Select
@distributiondatetime='07/22/2002',
@hour='02:02:10.000'

set @datetimevar = @distributiondatetime + ' ' + @hour

Select @datetimevar

By the way, ':00:00.000' is already a character string. Why are you converting it to varchar? Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
hi Terry L. Broadbent,

thanks, i made a silly mistake in that. sorry for that.
it is working fine now.

regards
pks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top