Click here to Skip to main content
15,909,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there. i have a table in database. my table's name is PhoneNumber.this table have these columns:
1- Prefix
2- Start
3- End
for example one record has following values:
Prefix= 347 , Start= 0000 , End = 9999.
now i want to create folling list:
3470000
3470001
3470002
.
.
.
3479999
how can i do this?( my RDBMS is sql server)
thanks
Posted
Updated 4-Feb-14 1:44am
v2

1 solution

Try a table valued function like this one:
SQL
CREATE FUNCTION GetNumberTable 
(
	@Prefix int
)
RETURNS 
@result TABLE 
(
	-- Add the column definitions for the TABLE variable here
	"myColumn" int
)
AS
BEGIN
	-- Fill the table variable with the rows for your result set
	
	declare @start int
	declare @end int
	declare @counter int

	SELECT @start=startcolumn,@end=endcolumn,@counter=startcolumn FROM myTable WEHRE prefixcolumn=@Prefix

	WHILE @counter < @end
	BEGIN
	  INSERT INTO @result (myColumn) VALUES (CAST(CONCAT(@Prefix,@counter) AS int))
	END

	RETURN
END


Note: There is some work to be done. I've only done a schematic example for you.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900