我想创建 SQL While 循环,我可以在其中基于 12 位数字和两个列范围内提取数千个字段。例如,
如果我在一个表中有 3 列
MasterKeyNumber---BB000Q000000
StartingNumber BB0000000001
EndingNumber - BB000Q00000022
我想创建一个 while 循环,它将从起始和结束数字中提取所有数字,并将显示哪个也将显示 MasterKey 数字
例如,
MasterKeyNumber---BB000Q000000
StartingNumber BB0000000001
StartingNumber BB0000000002
StartingNumber BB0000000003
StartingNumber BB0000000004
StartingNumber BB0000000005
StartingNumber BB0000000006
StartingNumber BB0000000007
StartingNumber BB0000000008
StartingNumber BB0000000009
StartingNumber BB0000000010
StartingNumber BB0000000011
StartingNumber BB0000000012
StartingNumber BB0000000013
StartingNumber BB0000000014
StartingNumber BB0000000015
StartingNumber BB0000000016
StartingNumber BB0000000017
StartingNumber BB0000000018
StartingNumber BB0000000019
StartingNumber BB0000000020
StartingNumber BB0000000021
StartingNumber BB0000000022
EndingNumber - BB000Q00000022
我只能通过使用“Between”“AND”之类的语句来提取一个或两个范围,但是如果我有显示多个不同数字和多个不同范围的范围,我该怎么做?
例如,我的查询一次拉一个范围
Select MasterKey, StartingNumber, EndingNumber, from TabelName
where StartingNumber Between 'BB0000000001' AND 'BB0000000022'
它只给出这个范围,但我有数千个不同的数字,它们将有多个范围,如 BB00000000004 到 BB00000000010 , BB0000000045 到 BB0000000066 , BB0000000088 到 BB0000000099
获取所有范围的 while 循环查询应该是什么?
提前致谢