-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
CREATE TABLE casetest(v TINYINT NOT NULL PRIMARY KEY)
GO

INSERT INTO casetest VALUES(1)
GO
INSERT INTO casetest VALUES(2)
GO
INSERT INTO casetest VALUES(10)
GO
INSERT INTO casetest VALUES(11)
GO

SELECT CASE WHEN v BETWEEN 1 AND 9 THEN '0' + CAST(v AS VARCHAR(2)) ELSE CAST(v AS VARCHAR(2)) END AS v2 FROM casetest
GO

DROP TABLE casetest
GO
