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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Create a string of Alpha-Text

Author  Topic 

simpleton
Starting Member

25 Posts

Posted - 2012-12-18 : 08:25:08
I need to create a string of text for reporting.
Example: My data select is '6'.
But my row should say 'A, B, C, D, E, F'
As in 6 digits alphanumeric digits separated w/commas.
Kind of crazy, but that's what I need.
My goal is for this to go in SSRS, so I can do VB if I have to.. but would rather stick with TSQL.

Any ideas? I'd love any advice you might have!
Thanks!!!

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-18 : 08:37:58
May this...?

DECLARE @sel int = 6, @res varchar(1000)=''
SELECT @res = COALESCE(@res+',' , ',') + CHAR( ASCII('A') + number)
FROM master..spt_values WHERE number<@sel AND type='p'
SELECT STUFF(@res, 1,1,'')


--
Chandu
Go to Top of Page

theboyholty
Posting Yak Master

226 Posts

Posted - 2012-12-19 : 04:09:44
Bandi, I have to say that's a fantastic bit of code there. Nice work.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk A Bury FC supporters website and forum
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-19 : 04:22:11
quote:
Originally posted by theboyholty

Bandi, I have to say that's a fantastic bit of code there. Nice work.

Thank you

--
Chandu
Go to Top of Page
   

- Advertisement -