需要有关测试 ISNUMERIC 语法的帮助,以防万一
我试图停止输入负值以在任何范围内进行处理,而不是如果它们是负值,则它们应该下降到第一个 case 语句的末尾作为“无效”。这不起作用,因为当我对 (-1000) 的输入运行测试时,我得到一行 <=50K。我担心我的语法是错误的,但不知道为什么。
ALTER FUNCTION [dbo].[FN_1ST_UPB_Bands]
(
@FN_1ST_UPB_Band int
)
RETURNS varchar(16)
AS
BEGIN
declare @Return varchar (16)
select @Return =
Case
When ISNUMERIC(@FN_1ST_UPB_Band)= 1 then
case
When @FN_1ST_UPB_Band is NULL then ' Missing'
When @FN_1ST_UPB_Band = 0 then ' 0'
When @FN_1ST_UPB_Band < = 50000 then ' <=50K'
When @FN_1ST_UPB_Band between 50000 and 100000 then ' 50-100'
When @FN_1ST_UPB_Band between 100000 and 150000 then '100-150'
When @FN_1ST_UPB_Band between 150000 and 200000 then '150-200'
When @FN_1ST_UPB_Band between 200000 and 250000 then '200-250'
When @FN_1ST_UPB_Band between 250000 and 300000 then '250-300'
When @FN_1ST_UPB_Band between 300000 and 350000 then '300-350'
When @FN_1ST_UPB_Band between 350000 and 400000 then '350-400'
When @FN_1ST_UPB_Band between 400000 and 450000 then '400-450'
When @FN_1ST_UPB_Band between 450000 and 500000 then '450-500'
When @FN_1ST_UPB_Band > 500000 then '500K+'
else null End
else 'Invalid' End
RETURN @return
End
I am trying to stop input of negative values to process in any of the ranges, rather if they are negative they should drop down to the end of the 1st case statement as 'Invalid'. This is not working as when I run a test against the input of (-1000) i get a row for <=50K. I am afraid my syntax is wrong, but not sure why.
ALTER FUNCTION [dbo].[FN_1ST_UPB_Bands]
(
@FN_1ST_UPB_Band int
)
RETURNS varchar(16)
AS
BEGIN
declare @Return varchar (16)
select @Return =
Case
When ISNUMERIC(@FN_1ST_UPB_Band)= 1 then
case
When @FN_1ST_UPB_Band is NULL then ' Missing'
When @FN_1ST_UPB_Band = 0 then ' 0'
When @FN_1ST_UPB_Band < = 50000 then ' <=50K'
When @FN_1ST_UPB_Band between 50000 and 100000 then ' 50-100'
When @FN_1ST_UPB_Band between 100000 and 150000 then '100-150'
When @FN_1ST_UPB_Band between 150000 and 200000 then '150-200'
When @FN_1ST_UPB_Band between 200000 and 250000 then '200-250'
When @FN_1ST_UPB_Band between 250000 and 300000 then '250-300'
When @FN_1ST_UPB_Band between 300000 and 350000 then '300-350'
When @FN_1ST_UPB_Band between 350000 and 400000 then '350-400'
When @FN_1ST_UPB_Band between 400000 and 450000 then '400-450'
When @FN_1ST_UPB_Band between 450000 and 500000 then '450-500'
When @FN_1ST_UPB_Band > 500000 then '500K+'
else null End
else 'Invalid' End
RETURN @return
End
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ISNUMERIC
在INT
字段上始终为 true,您可以放心地丢弃它。试试这个:
ISNUMERIC
is always true on anINT
field, you can safely throw it away.Try this:
在这种情况下(没有双关语)
这样做是
因为 -1000 小于 50000
in that case (no pun intended)
do this
because -1000 is less than 50000
因为它们是按顺序求值的,所以 -1000 是 <= 50000,因此它求值为 true 并返回“<= 50000”。您需要
1 到 49999
之间的值(不是 50000,因为您有 50000 在 2 种情况下会评估 true)。Because they are evaluated in order, -1000 is <= 50000, so it evaluates as true and returns the "<= 50000". You need
between 1 and 49999
instead (Not 50000 as you had 50000 would evalute true in 2 cases).那么-1000不是小于50000吗?您不需要这种情况吗:
当 @FN_1ST_UPB_Band 在 0 和 49999 之间时,则 ' <=50K'
Well isn't -1000 less than 50000? Don't you need that case to be:
When @FN_1ST_UPB_Band between 0 and 49999 then ' <=50K'