Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:10:54+00:00 2026-06-12T06:10:54+00:00

DECLARE @tableHTML NVARCHAR(MAX) ; SET @tableHTML = N'<H1>Report Heading</H1>’ + N'<table border=1>’ + N'<th>Check

  • 0
DECLARE @tableHTML  NVARCHAR(MAX) ;

SET @tableHTML =
    N'<H1>Report Heading</H1>' +
    N'<table border="1">' +
    N'<th>Check Number</th>' +
    N'<th>Last Operator Date</th>' +
    N'<th>Last Timestamp</th>' +
    N'<th>Run Date</th>' +
    N'<th>Issued Check Number</th>' +
    N'<th>Error Description</th>' +
    '<tr>' +
    CAST ( ( SELECT td = S.CHK_NUM,       '',
                    td = S.LAST_OPER_ID, '',
                    td = S.LAST_TIMESTMP, '',
                    td = S.RUN_DT, '',
                    td = ISNULL(S.RE_ISSUE_CHK_NUM,-1), '',
                    td = ISNULL(S.ERR_DESC,'<null>'), ''
              FROM STAGNG_CDDP_ERR_RCD S
              FOR XML PATH('tr'), TYPE 
    ) AS NVARCHAR(MAX) ) +
    N'</table>' ;

PRINT @tableHTML

If I attempt to substiture -1 with a varchar literal ‘(Null)’, I get the error

Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value 'Null' to data type int.

I would prefer to display if the RE_ISSUE_CHK_NUM is null, but that field is an int and i believe the “TYPE” param is forcing teh returned value to match the original column’s type.

How do I modify the output so all of teh columns are text and hence formattable?

Edit

When I try this…

DECLARE @tableHTML  NVARCHAR(MAX) ;

SET @tableHTML =
    N'<H1>Report Heading</H1>' +
    N'<table border="1">' +
    N'<th>Check Number</th>' +
    N'<th>Last Operator Date</th>' +
    N'<th>Last Timestamp</th>' +
    N'<th>Run Date</th>' +
    N'<th>Issued Check Number</th>' +
    N'<th>Error Description</th>' +
    '<tr>' +
    CAST ( ( SELECT td = S.CHK_NUM,       '',
                    td = S.LAST_OPER_ID, '',
                    td = S.LAST_TIMESTMP, '',
                    td = S.RUN_DT, '',
                    --td = ISNULL(S.RE_ISSUE_CHK_NUM,-1), '',
                    td = CONVERT(NVARCHAR(16), ISNULL(S.RE_ISSUE_CHK_NUM,'(Null)')), '',
                    td = ISNULL(S.ERR_DESC,'<null>'), ''
              FROM STAGNG_CDDP_ERR_RCD S
              FOR XML PATH('tr'), TYPE 
    ) AS NVARCHAR(MAX) ) +
    N'</table>' ;

PRINT @tableHTML

I get this:

Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value '(Null)' to data type int.

It’s tthe Check Number field that is Null that is numeric that i would like to display the string ‘Null’ in the HTML.

Is it the TYPE param that is the issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:10:55+00:00Added an answer on June 12, 2026 at 6:10 am

    change this line

    td = CONVERT(NVARCHAR(16), ISNULL(S.RE_ISSUE_CHK_NUM,'(Null)')), '',
    

    to

    td = CASE WHEN S.RE_ISSUE_CHK_NUM IS NULL THEN '<NULL>' ELSE  CONVERT(NVARCHAR(16), S.RE_ISSUE_CHK_NUM) END , '',
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

declare @TableName nvarchar(max) set @TableName='addresses' DECLARE @sql NVARCHAR(MAX) set @sql= 'create table #tempadd (
DECLARE @DatabaseName NVARCHAR(max); SET @DatabaseName = 'MainDb' USE @DatabaseName Wouldn't work. How to make
DECLARE @str NVARCHAR(MAX) SET @str = '<bands > <title>my bands</title> <band> <fullName>beatles</fullName> <members> <member
Declare @count nvarchar(max) set @count ='select COUNT(*) from '+ @tablename+'' if( @count =0 )
declare @mydata nvarchar(4000) set @mydata = '36|0, 77|5, 132|61' I have this data that
DECLARE @dbfilepath nvarchar(128) SET @dbfilepath = 'C:\SqlDataFiles\Cache.mdf' GO USE [master] GO CREATE DATABASE [Cache]
DECLARE @result varchar(MAX) SELECT NAME FROM Table WHERE ID = @Id I need to
DECLARE @Item as char(32) declare @result varchar(max) SET @Item = 'FL1823' with Bom (
Declare @ID nvarchar(14) = '12345678912345' DECLARE @Key int = (SELECT key FROM table WHERE
declare @node int = 9044; DECLARE @sqlCommand NVARCHAR(MAX) = ( 'SELECT * FROM [@node].[database_name].dbo.table_name'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.