Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
If i have string like 'Transit' then how do I return a table asT 3R 2A 1N 2S 1I 1-----------------------------------------------------------------------------------------------Ashley Rhodes
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts
Posted - 2009-08-11 : 11:51:37
What do those numbers mean?
ashley.sql
Constraint Violating Yak Guru
299 Posts
Posted - 2009-08-11 : 12:32:30
the total number of characters in expressionsorry i got it wrongTRANSITST 2R 1A 1N 1S 2I 1-----------------------------------------------------------------------------------------------Ashley Rhodes
TG
Master Smack Fu Yak Hacker
6065 Posts
Posted - 2009-08-11 : 13:35:24
Here's one way:
declare @s varchar(200)set @s = 'Transits' select c as letter ,count(*) as letter_countfrom ( select substring(s, number, 1) c ,n.number from (select @s [s]) d join master..spt_values n on n.type = 'P' and n.number between 1 and len(s) ) dgroup by corder by min(number)OUTPUT:letter letter_count------ ------------t 2r 1a 1n 1s 2i 1