Showing posts with label cloumn. Show all posts
Showing posts with label cloumn. Show all posts

Sunday, March 11, 2012

Error converting data type varchar to numeric.

HI
i have a very big problem.
i have a cloumn name Revenue and i have differt types of revenue in it such as A, B, C.
what i want to do is that i want to say that when the Revenue column is A then sum the tola mount and put in in a new column name A when b then again same thing.
this is my code

case when Revenue='A' then Sum(total_amt) else ' ' end as A

but it is giving me and error Error converting data type varchar to numeric.
please help

Quote:

Originally Posted by voroojak

HI
i have a very big problem.
i have a cloumn name Revenue and i have differt types of revenue in it such as A, B, C.
what i want to do is that i want to say that when the Revenue column is A then sum the tola mount and put in in a new column name A when b then again same thing.
this is my code

case when Revenue='A' then Sum(total_amt) else ' ' end as A

but it is giving me and error Error converting data type varchar to numeric.
please help


first, why the error.

because your case statement said when revenue = 'A' return the sum of total_amt else return blank...the case statement should return (the then part and the else part) the same datatype or at least can be converted to the same datatype.

try ...else sum(0) end as A, ...or ....else 0 end as A

Sunday, February 26, 2012

error comming at insert stmt

assume connection is established and photo cloumn as data type as image in sql table.

str_insert ="INSERT INTO SIS_TeachingStaff VALUES('TSMT2','V.RAJANIKANTH','LECTURER','TEACHING STAFF','Msc(Maths)','" & Emp_pic.Image &"' "

cmd =New SqlCommand(str_insert, conn)

cmd.Connection = conn

cmd.ExecuteNonQuery()

Error at insert stmt: Operator '&' is not defined for types 'string' and 'system.drawing.image'

Hi

")" is missed at the end .Try this:

str_insert ="INSERT INTO SIS_TeachingStaff VALUES('TSMT2','V.RAJANIKANTH','LECTURER','TEACHING STAFF','Msc(Maths)','" & Emp_pic.Image &"') "