英文:
Select a range name - 'DisplayName' from a given table if it exist in the range, defined in table for a given number
问题
以下是翻译好的部分:
给定的临时表结构如下所示:
CREATE TABLE #TempTable (
DisplayName VARCHAR(50),
Value1 VARCHAR(50),
Value2 VARCHAR(50)
)
INSERT INTO #TempTable
VALUES
('569-580','569','580')
('581-592','581','592')
('593-607','593','607')
('608-620','608','620')
SELECT * FROM #TempTable
如果用户提供一个数字,我需要获取DisplayName,然后查看该数字是否存在于这个范围内,如下所示:
如果给定的数字是606,则输出应为:
'593-607'
如果给定的数字是608,则输出应为:
'608-620'
英文:
For a given temp table structure is as given below:
CREATE TABLE #TempTable (
DisplayName VARCHAR(50),
Value1 VARCHAR(50),
Value2 VARCHAR(50)
)
INSERT INTO #TempTable
VALUES
('569-580','569','580')
('581-592','581','592')
('593-607','593','607')
('608-620','608','620')
SELECT * FROM #TempTable
I need get DisplayName if user provide a number then that number exists in that range like<br>
if given number is 606 then output should be:
'593-607'<br>
if given number is 608 then output should be:
'608-620'
答案1
得分: 0
DECLARE @GivenNumber INT = 606
SELECT DisplayName
FROM #TempTable1
WHERE @GivenNumber BETWEEN CAST(Value1 AS INT) AND CAST(Value2 AS INT)
英文:
DECLARE @GivenNumber INT = 606
SELECT DisplayName
FROM #TempTable1
WHERE @GivenNumber BETWEEN CAST(Value1 AS INT) AND CAST(Value2 AS INT)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论