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)
 cast int to varchar problem

Author  Topic 

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-01-27 : 06:26:35
hi try to convert int to char in a query

cast((ht_booknew.bookingno1+'-'+ht_booknew.bookingno2),VAR(200)) as bookingno

but it throws the error
Msg 195, Level 15, State 10, Line 1
'varchar' is not a recognized built-in function name.

Desikankannan

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-01-27 : 06:36:11
Replace with

cast((ht_booknew.bookingno1+'-'+ht_booknew.bookingno2) as VARCHAR(200)) as bookingno
Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-01-27 : 06:46:38
hi,

again its throwing error like

Arithmetic overflow error converting varchar to data type numeric.


quote:
Originally posted by MIK_2008

Replace with

cast((ht_booknew.bookingno1+'-'+ht_booknew.bookingno2) as VARCHAR(200)) as bookingno



Desikankannan
Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-01-27 : 06:49:06

hi
this is my query

select cast((ht_booknew.bookingno1+'-'+ht_booknew.bookingno2) as varchar(300))as bookingno from ht_booknew

error throwing

Msg 8115, Level 16, State 6, Line 1
Arithmetic overflow error converting varchar to data type numeric.
quote:
Originally posted by MIK_2008

Replace with

cast((ht_booknew.bookingno1+'-'+ht_booknew.bookingno2) as VARCHAR(200)) as bookingno



Desikankannan
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-01-27 : 06:57:02
1) What are the datatypes of the BookingNo1 and No2 fields? Seems to be Numeric with the length of?

2) are you trying to concat the BookingNo1 and BookingNo2 fields, separating both with a -?
Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-01-27 : 07:43:24
quote:
Originally posted by MIK_2008

1) What are the datatypes of the BookingNo1 and No2 fields? Seems to be Numeric with the length of?

2) are you trying to concat the BookingNo1 and BookingNo2 fields, separating both with a -?



Desikankannan
Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-01-27 : 07:44:47

yes i tryint to concat the bookingno1 and bookingno2 fields

quote:
Originally posted by MIK_2008

1) What are the datatypes of the BookingNo1 and No2 fields? Seems to be Numeric with the length of?

2) are you trying to concat the BookingNo1 and BookingNo2 fields, separating both with a -?



Desikankannan
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-01-27 : 07:52:51
Go with the following :)



Select
cast (ht_booknew.bookingno1 as varchar(100))+ ' - ' + cast(ht_booknew.bookingno2 as varchar(100))
as bookingno
from ht_booknew
Go to Top of Page
   

- Advertisement -