I have a case statement which looks like this
SELECT
Location,
CASE WHEN id BETWEEN 1 AND 7 THEN '05' ELSE '01' END AS id
FROM Locations
This however returns 5 or 1 without the leading zero.
I’ve tried CAST('05' AS sql_variant) but I’m going to use this select as an insert statement into a table and its a nvarchar field so it doesnt like that.
Any ideas? Thanks
I tried your query on SQL 2008R2 and it works fine..
You could always do this:
Are you binding the value in a variable or are you inserting directly in another table?
ex:
INSERT INTO table2 SELECT …