我想选择数据。如果它是NULL
,将其替换为0并且它是收入所以我需要转换为圆形,这个数据我需要在图表上显示范围明智但问题是我的数据库中的数据不是数字意味着一些特殊字符有' - ','/'或其他东西,我无法从我的数据库中删除这些字符我想更改我的查询它是字符串,它将替换为= 0
我的查询如下:
SELECT ROUND(ISNULL(REVENUE, '0'), 0) AS Revenue,
COUNT(ID) AS Counts,
CASE
WHEN ROUND(ISNULL(REVENUE, '0'), 0) = 0
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 5 THEN 1
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 5
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 10 THEN 2
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 10
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 20 THEN 3
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 20
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 50 THEN 4
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 50
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 100 THEN 5
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 100
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 250 THEN 6
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 250
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 500 THEN 7
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 500
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 1000 THEN 8
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 1000
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 5000 THEN 9
WHEN ROUND(ISNULL(REVENUE, '0'), 0) > 5000
AND ROUND(ISNULL(REVENUE, '0'), 0) <= 10000 THEN 10
ELSE 11
END AS ranges
FROM CT_GLOBALDATA
WHERE CREATEDDATE BETWEEN GETDATE() - 30 AND GETDATE()
GROUP BY REVENUE
SELECT REVENUE
FROM CT_GLOBALDATA
答案 0 :(得分:0)
我创建了函数,它工作正常。 我正在上传我的功能以供将来参考
创建功能dbo.udf_GetNumeric_Nitish
(@strAlphaNumeric VARCHAR(256))
退货变量(256)
AS
BEGIN
声明@test varchar(256)
声明@intAlpha int
选择@intAlpha = ISNUMERIC(@strAlphaNumeric)
if @ intAlpha = 1
设置@ test = @ strAlphaNumeric
否则
设置@ test ='0'
返回@test
结束