Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Generate a number list from a string value
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

7 Posts

Posted - 10/22/2013 :  16:28:51  Show Profile  Reply with Quote
I have a single column that has string values like ['61000-61055']. I am trying to get the list of numbers that would start with 61000, and end with 61055. The actual data has the beginning and ending quotes as part of the string. My output would have a number on each row.

Using SQL Server 2008 R2


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 10/22/2013 :  16:52:38  Show Profile  Reply with Quote
Are all the rows in the table consistently of the same pattern - i.e., a left square bracket, followed by a single quote, followed by a number, followed by a hyphen, followed by a number then single quote and square bracket?

Edited by - James K on 10/22/2013 16:52:50
Go to Top of Page

Starting Member

7 Posts

Posted - 10/22/2013 :  18:39:52  Show Profile  Reply with Quote
They are all consistent with a single quote, number, hyphen, number, then single quote'
exp. '61000-61055'

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/23/2013 :  02:07:51  Show Profile  Reply with Quote

SELECT StartVal + v.number
SELECT REPLACE(LEFT(Col,CHARINDEX('-',Col)-1),'[''','') AS StartVal,
REPLACE(STUFF(Col,1,CHARINDEX('-',Col),''),''']','') AS EndVal
FROM table 
CROSS JOIN master..spt_values v
WHERE v.type = 'p'
AND StartVal + v.number <= EndVal

SQL Server MVP
Go to Top of Page

Starting Member

7 Posts

Posted - 10/23/2013 :  16:42:40  Show Profile  Reply with Quote

I'll give that a try.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000