我正在尝试做一个 HTML 表格,但我遇到了它不返回值的问题。 这个例子显示了我的结果。
是否可以编写脚本,如果没有任何结果,它将返回 0? 我尝试了 ISNULL 方法,但它没有返回任何值。
我期待通过使用 ISNULL 方法,它会在结果中返回一个 0,但它并没有这样做。
Select ISNULL(body,0) from [EMAIL_MATRIX]
where body NOT IN(
SELECT c.Body
FROM [dbo].[EMAIL_DETAILS] a
INNER JOIN [Email_matrix] c
ON SUBSTRING(a.Subject,5,LEN(a.Subject)-4) = c.Subject
and a.Body LIKE CONCAT('%', c.body, '%')
where Cast(a.Send as DAte) = '2022-10-04')
试试这个,
Select REPLACE(ISNULL(body,0),'',0) from [EMAIL_MATRIX]
where body NOT IN(
SELECT c.Body
FROM [dbo].[EMAIL_DETAILS] a
INNER JOIN [Email_matrix] c
ON SUBSTRING(a.Subject,5,LEN(a.Subject)-4) = c.Subject
and a.Body LIKE CONCAT('%', c.body, '%')
where Cast(a.Send as DAte) = '2022-10-04')
试试这个:
WITH DataSource AS
(
Select ISNULL(body,0) AS body
from [EMAIL_MATRIX]
where body NOT IN
(
SELECT c.Body
FROM [dbo].[EMAIL_DETAILS] a
INNER JOIN [Email_matrix] c
ON SUBSTRING(a.Subject,5,LEN(a.Subject)-4) = c.Subject
and a.Body LIKE CONCAT('%', c.body, '%')
where Cast(a.Send as DAte) = '2022-10-04'
)
)
SELECT body
FROM DataSource
WHERE EXISTS(SELECT 1 FROM DataSource)
UNION ALL
SELECT NULL
WHERE NOT EXISTS(SELECT 1 FROM DataSource)