SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
i work on sql server 2019 is null not display on dynamic sql
what i try is
declare @s2 varchar(max) = ''
set @s2 =--'select FROM Extractreports.dbo.FinalReportDashBoardNewReplacement WITH(NOLOCK)'
concat(
'select ',
STUFF((
SELECT ',' + ' + isnull(name,'') + '
FROM Extractreports.sys.columns
WHERE [object_id] = OBJECT_ID(N'Extractreports.dbo.FinalReportDashBoardNewReplacement')
FOR XML PATH('')
), 1, 1, ''),'FROM Extractreports.dbo.FinalReportDashBoardNewReplacement WITH(NOLOCK)')
select @s2
issue when see result it show as
select + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + , + isnull(name,'') + FROM Extractreports.dbo.FinalReportDashBoardNewReplacement WITH(NOLOCK)
i need instead of name column name display
but this not happen
Hi @ahmed salah
Try the following modifications:
SELECT ',' + ' + isnull(name,'') + '
to SELECT ',' + 'isnull(' + name + ','''') '
FROM Extractreports.dbo.FinalReportDashBoardNewReplacement WITH(NOLOCK)
to avoid syntax error. declare @s2 varchar(max) = '' Best regards,
LiHong
Please try with
declare @s2 varchar(max) = ''
set @s2 =--'select FROM Extractreports.dbo.FinalReportDashBoardNewReplacement WITH(NOLOCK)'
concat(
'select ',
STUFF((
SELECT ',' + isnull(name,'')
FROM sys.columns
WHERE [object_id] = OBJECT_ID(N'Extractreports.dbo.FinalReportDashBoardNewReplacement')
FOR XML PATH('')
), 1, 1, ''),'FROM Extractreports.dbo.FinalReportDashBoardNewReplacement WITH(NOLOCK)')
select @s2
Change:
...
SELECT ',' + ' + isnull(name,'') + '
...
to:
...
SELECT ',' + ' + isnull(' + name + ','') + '
...