我正在尝试将查询结果转换为HTML布局。当使用硬编码表和数据库我得到结果,但当我使用动态变量数据库和表时,我收到错误。以下是我使用的查询。你能帮我解决这个问题。
declare @query nvarchar(max)
Declare @DB varchar(3)
set @DB = 'EDO'
set @query =
cast(('SELECT DISTINCT td=SUBSTRING(LOT.KEY_FIELDS,1,15) ,'', td=SUBSTRING(LOT.KEY_FIELDS,16,15),'',
td=SUBSTRING(LOT.SUN_DATA,1,8) ,'',SUBSTRING(LOT.SUN_DATA,9,40) ,''
FROM SSRFMSC LOT LEFT OUTER JOIN SMMFMOV'+@DB+' INV ON SUBSTRING(LOT.KEY_FIELDS,16,15) = INV.RECPT_REF AND
SUBSTRING(LOT.KEY_FIELDS,1,15) = INV.ITEM_CODE
WHERE
INV.ITEM_CODE IS NULL
AND
LOT.SUN_DB =''' +@DB+ ''' AND LOT.SUN_TB = ''MIV''
and SUBSTRING(LOT.SUN_DATA,1,8) > (SELECT CONVERT(VARCHAR(8), GETDATE(), 112) AS [YYYYMMDD]) ')
for xml path('tr'),type) as nvarchar(max))+N'< /table>'
select @query
“无法添加HTML布局”