SQL Server Is there a way to return a value instead of blank for SQL? [closed]

jyztefdp  于 2023-04-04  发布在  其他
关注(0)|答案(2)|浏览(104)

Closed. This question needs debugging details . It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem . This will help others answer the question.

Closed 5 days ago.
The community is reviewing whether to reopen this question as of 5 days ago.
Improve this question

I am trying to do a HTML table but i am having troubles where it does not return a value. This example shows my result. Sample Image

Is it possible to script that if there isnt any result, it will return 0?

I tried ISNULL method and it does not return me any values.

I am expecting that by using the ISNULL method, it will return a 0 in the result, but it doesn't do so.

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')
vwoqyblh

vwoqyblh1#

Try this:

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)
piv4azn7

piv4azn72#

Try this,

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')

相关问题