Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

Conversion failed when converting the varchar value to data type int.

I get the following error:

Conversion failed when converting the varchar value 'December' to data type int.

for the following sql string


select * from frmRegistrationCSW where Fiscal = 2013 and Month(EntryTime) ='December'
and frmRegistrationCSWCheck11 = 1

How do I convert it?
Avatar of mimran18
mimran18
Flag of United Arab Emirates image

Because [EntryTime] field is int and you are comparing it with 'December'

Make it like Month(EntryTime) =12 then it will work
Avatar of al4629740

ASKER

How can I change Month(EntryTime)?

I would like to keep it as ='December'
Then you can do it like this

Datename (mm,[EntryTime]) ='December'
Does that work if I do this, using the < symbol

Datename (mm,[EntryTime]) <= 'December'
No, it will not wotk, Better you need to convert it into int and use it.
you can make a case statement if it is december then return 12 and can use it here.
Why do both of this statements produce different results?


select * from frmRegistrationCSW where Fiscal = 2013 and EntryTime <= '12/31/2012' and frmRegistrationCSWCheck11 = 1



select * from frmRegistrationCSW where Fiscal = 2013 and Datename (mm,[EntryTime]) <= 'December' and frmRegistrationCSWCheck11 = 1

Open in new window

I don't think that would make sense (because doing a character comparison).  Month(EntryTime)<=12 would normally make more sense except that generally that should always be true (I am unaware of any month being greater than 12 :-)).  Perhaps you would like to describe what it is you are trying to achieve?
Case statement?

Do you have an example?
SOLUTION
Avatar of Aeriden
Aeriden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial