I am facing problem while using CAST function. Here i am using SUM function inside CAST function and assigning the returned value to a variable which is of varchar datatype of length 100. The variable which i am using inside SUM function is big int.
I am doing like this:
@.hour = (select CAST(SUM(totaltime) as varchar(100) from 'Table name'
It was getting error like:
Unable to convert varchar datatype to bigint.
How can i resolve this problem..
Regards,
SaratStart by posting code that will actually compile... Also, give us the data types of each column you are looking at.|||Actually the following code compiles and works as I would expect:
Create Table #X(x bigint)
Insert Into #X Values(1)
Insert Into #X Values(2)
Declare @.hour varchar(100)
Set @.hour = (select CAST(SUM(x) as varchar(100)) from #X)
Select @.hour
Drop Table #X
So I don't really see the problem... I pretty-much copied and pasted your line
|||Just wondering - why not use:select @.hour = CAST(SUM(x) as varchar(100)) from #X
rather than: SET @.hour = (SELECT ....
No comments:
Post a Comment