• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

SQL CAST or CONVERT

I'm trying to convert an INT to VARCHAR in my CASE statement by using the following:

SELECT CASE
		WHEN CAST(AuthenticationMode AS VARCHAR(7)) = '0' THEN 'Mixed'
		WHEN CAST([AuthenticationMode] AS VARCHAR(7)) = '1' THEN 'Windows'
	   ELSE [AuthenticationMode]
	   END AS 'AuthenticationMode'

Open in new window


But I get the following error:
Conversion failed when converting the varchar value 'Mixed' to data type int.

Any ideas?

Best regards

Rasmus
0
Coloplast
Asked:
Coloplast
1 Solution
 
Lokesh B RDeveloperCommented:
Hi,

SELECT (CASE
            WHEN CAST(AuthenticationMode AS VARCHAR(7)) = '0' THEN 'Mixed'
            WHEN CAST([AuthenticationMode] AS VARCHAR(7)) = '1' THEN 'Windows'
         ELSE CAST([AuthenticationMode] AS VARCHAR)
         END) AS 'AuthenticationMode'
0
 
ColoplastAuthor Commented:
Thanks for the fast solution :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now