Westside2004
asked on
Conversion failed when converting the varchar value 'Not Relevant' to data type int.
Hi,
I am using SQL 2008.
I'm trying to write this query with a CASE statement and I'm getting this error:
Conversion failed when converting the varchar value 'Not Relevant' to data type int.
I understand why, because one column is of int datatype and the other is varchar. How can I CAST/CONVERT this so the query runs successfully.
Here is my query that throws the error:
Customer_Level is a column with "int" datatype.
Any help appreciated....
I am using SQL 2008.
I'm trying to write this query with a CASE statement and I'm getting this error:
Conversion failed when converting the varchar value 'Not Relevant' to data type int.
I understand why, because one column is of int datatype and the other is varchar. How can I CAST/CONVERT this so the query runs successfully.
Here is my query that throws the error:
SELECT
Customer_ID,
Customer_Level =
CASE Customer_Level
WHEN '99' THEN CAST('Not Relevant' AS int)
ELSE Customer_Level END,
First_Name
FROM Customer
Customer_Level is a column with "int" datatype.
Any help appreciated....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can not cast 'No Relevant' to INT
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
pourfard is right
You could do like
SELECT Customer_ID,
CASE Customer_Level
WHEN 99 THEN 'Not Relevant'
ELSE CAST(Customer_Level AS VARCHAR(20))
END AS Customer_Level,
First_Name
FROM Customer
You could do like
SELECT Customer_ID,
CASE Customer_Level
WHEN 99 THEN 'Not Relevant'
ELSE CAST(Customer_Level AS VARCHAR(20))
END AS Customer_Level,
First_Name
FROM Customer
ASKER
Thanks a bunch. Worked...