我有一个存储过程如下:
CREATE PROC [dbo].[Incidents]
(@SiteName varchar(200))
AS
SELECT
(
SELECT SUM(i.Logged)
FROM tbl_Sites s
INNER JOIN tbl_Incidents i
ON s.Location = i.Location
WHERE s.Sites = @SiteName AND i.[month] = DATEADD(mm, DATEDIFF(mm, 0, GetDate()) -1,0)
GROUP BY s.Sites
) AS LoggedIncidents
'tbl_Sites contains a list of reported on sites.
'tbl_Incidents contains a generated list of total incidents by site/date (monthly)
'If a site doesn't have any incidents that month it wont be listed.
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是网站本月没有任何事件,因此当我运行此sproc时,我得到为该网站返回的NULL值,但我需要返回一个零/ 0来在图表中使用在SSRS.
我尝试过使用coalesce并且无效.
SELECT COALESCE(SUM(c.Logged,0))
SELECT SUM(ISNULL(c.Logged,0))
Run Code Online (Sandbox Code Playgroud)
有没有办法正确地格式化? …
我在更新桌子时遇到了问题,我确信它很直接,但我在这里绕圈转.
我要更新的表'table1'数据格式如下:
[Month] Figure
----------------------------------
2010-05-01 00:00:00.000 1.0000
2010-06-01 00:00:00.000 1.0000
2010-07-01 00:00:00.000 1.0000
2010-08-01 00:00:00.000 1.0000
Run Code Online (Sandbox Code Playgroud)
包含更新数字的表'data1'格式如下:
[Month] Figure
----------------------------------
2010-05-01 00:00:00.000 0.7212
2010-08-01 00:00:00.000 1.2351
Run Code Online (Sandbox Code Playgroud)
我正在使用的SQL和错误消息如下.
UPDATE t1
SET t1.figure = (SELECT figure from data1)
FROM table1 t1 JOIN data1 d1
ON (t1.[month] = d1.[month])
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has …Run Code Online (Sandbox Code Playgroud)