I am trying to generate a series of alphabets, using SQL Server.
Suppose I have a tables as follows
DECLARE @Funding TABLE (FundingDetailID INT,FundingID INT, DetailDescription VARCHAR(50))
INSERT INTO @Funding (FundingDetailID ,FundingID , DetailDescription) VALUES (1,107,'Desc 1')
INSERT INTO @Funding (FundingDetailID ,FundingID , DetailDescription) VALUES (1,107,'Desc 2')
INSERT INTO @Funding (FundingDetailID ,FundingID , DetailDescription) VALUES (1,107,'Desc 3')
I am trying to obtain the following result.
a) Desc 1
b) Desc 2
c) Desc 3
How do I generate “a)”, “b)”, … ? I am not allowed to add any extra temp table or table variable for storing the alphabets initially. They should be generated.
And this is to be done in SQL Server 2005.
Any thoughts ?
Thanks
Lijo Cheeran Joseph
Use ROW_NUMBER() as follows
DECLARE @Funding TABLE (FundingDetailID INT,FundingID INT, DetailDescription VARCHAR(50))
INSERT INTO @Funding VALUES (1,107,'Desc 1')
INSERT INTO @Funding VALUES (1,107,'Desc 2')
INSERT INTO @Funding VALUES (1,107,'Desc 3')
SELECT CHAR (CAST (96+ROW_NUMBER() OVER (Order BY FundingDetailID) AS VARCHAR)) + ') ' + DetailDescription
FROM @Funding
-----------------------------------------------------
a) Desc 1
b) Desc 2
c) Desc 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With