如何在一个范围内创建数字? [英] how can create number in a range?

查看:67
本文介绍了如何在一个范围内创建数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我在数据库中有一个表。我的表名是PhoneNumber。这个表有以下列:

1-前缀

2-开始

3-结束

例如一条记录具有以下值:

前缀= 347,开始= 0000,结束= 9999.

现在我想创建下拉列表:

3470000

3470001

3470002







3479999

我该怎么做?(我的RDBMS是sql server)

谢谢

解决方案

尝试像这样的表值函数:

 创建  FUNCTION  GetNumberTable 

@ Prefix int

退货
@ result TABLE

- 在此处添加TABLE变量的列定义
myColumn int

AS
BEGIN
- 使用结果集的行填充表变量

声明 @ start int
声明 @ end int
声明 @ counter int

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

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

返回
END





注意:还有一些工作要做。我只为你做了一个示意图。


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

解决方案

Try a table valued function like this one:

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.


这篇关于如何在一个范围内创建数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆