我在网络上看得相当广泛,但是我还没有找到一个我正在尝试编写的查询,它将值传递给html表格以进行电子邮件输出。对于其中一列,我想传递一个链接。有没有办法做到这一点?我目前收到错误的说法
"Conversion failed when converting the varchar value '<a href="http://testServer/webnow/index.jsp?action=filter&username=anonymous&drawer=AP-General&folder=' to data type int."
请参阅下面的代码片段。
SET @Body = COALESCE(@Body + '', '') +
CAST((SELECT DISTINCT Api.GLAccountID,
api.CostCenterNumber,
api.VendorNumber,
--SPECIFICALLY THIS LINE...
'<a href="http://testServer/webnow/index.jsp?action=filter&username=anonymous&drawer=AP-General&folder=' + v.VendorID + '&tab=' + api.Invoice + '">' + api.Invoice + '</a>'
FROM dummytable api
FOR XML RAW('TR'), ELEMENTS) AS NVARCHAR(MAX)) + '</TABLE>'
答案 0 :(得分:0)
我假设v.VendorID
的值属于INT
类型。查看其他字段(v.VendorID
等),它们也可以是INT
或NUMERIC
类型,因此我也将它们作为VARCHAR
投放,您可能需要使用数据类型的大小。
这应该有所帮助:
SET @Body = COALESCE(@Body + '', '') +
CAST((SELECT DISTINCT Api.GLAccountID,
api.CostCenterNumber,
api.VendorNumber,
--SPECIFICALLY THIS LINE...
'<a href="http://testServer/webnow/index.jsp?action=filter&username=anonymous&drawer=AP-General&folder=' + CAST(v.VendorID AS VARCHAR(50)) + '&tab=' + CAST(api.Invoice AS VARCHAR(50)) + '">' + CAST(api.Invoice AS VARCHAR(50)) + '</a>'
FROM dummytable api
FOR XML RAW('TR'), ELEMENTS) AS NVARCHAR(MAX)) + '</TABLE>'