Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

Increment the string value letter by letter for every row using SQL server

5.00/5 (2 votes)
5 Oct 2011CPOL 11.5K  
WITH tempTable(Column1)AS( SELECT 'chaitanya' [Column1] UNION ALL SELEC`T SUBSTRING(Column1,1,LEN(Column1)-1) FROM tempTable WHERE LEN(Column1)>0)SELECT * FROM tempTable ORDER BY LEN(Column1)Result:cchchachaichaitchaitachaitanchaitanychaitanya
WITH tempTable(Column1)
AS
(
   SELECT 'chaitanya' [Column1] UNION ALL SELEC`T SUBSTRING(Column1,1,LEN(Column1)-1) FROM tempTable WHERE LEN(Column1)>0
)
SELECT * FROM tempTable ORDER BY LEN(Column1)


Result:
VB
c
ch
cha
chai
chait
chaita
chaitan
chaitany
chaitanya

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)