如何在一个范围内创建数字?

编程入门 行业动态 更新时间:2024-10-25 21:23:44
本文介绍了如何在一个范围内创建数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好。我在数据库中有一个表。我的表名是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.

更多推荐

如何在一个范围内创建数字?

本文发布于:2023-11-09 23:07:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573689.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   数字   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!