Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert INT to VACHAR in CASE statement

Author  Topic 

Analyzer
Posting Yak Master

115 Posts

Posted - 2014-03-11 : 10:46:29
Hi. Wish to convert an INT value from the registry to a VARCHAR but not sure how to convert from INT to VARCHAR within a CASE statement. Below is my code which current fails on "Conversion failed when converting the varchar value 'Automatic' to data type int". Any ideas please?


DECLARE Var1 INT
EXECUTE master.dbo.xp_instance_regread
@rootkey = N'HKEY_LOCAL_MACHINE',
@key = N'SYSTEM\CurrentControlSet\Services\SQLServerAgent',
@value_name = N'Start',
@value = @Var1 OUTPUT

select
case
WHEN @Var1 =4 THEN 'Disabled'
WHEN @Var1 =3 THEN 'Manual'
WHEN @Var1 =2 THEN 'Automatic'
ELSE 0
END
FROM sys.dm_os_sys_info

select @Var1

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-03-11 : 10:57:45
try ELSE '0' instead of ELSE 0




Too old to Rock'n'Roll too young to die.
Go to Top of Page

Analyzer
Posting Yak Master

115 Posts

Posted - 2014-03-11 : 11:22:59
Boom. That worked great. Thanks you
Go to Top of Page
   

- Advertisement -