您好,我正在制作一个存储过程,但在输出带有打印的代码时遇到问题,因为稍后我需要将变量写入临时数据库。这是代码:
SELECT
fmsTotalAmount + fmsAirTotalAmount + fmsProjectsTotalAmount TotalAmount,
fmsRelationAmount + fmsAirRelationAmount + fmsProjectsRelationAmount TotalRelationAmount
FROM (
SELECT
SUM(
CASE WHEN fms1.currency != 'EUR'
THEN fms1.Amount * fms1.Rate
ELSE ISNULL(fms1.Amount, 0) END) fmsTotalAmount,
SUM(
CASE WHEN fms1.relationcode = 'SHIP02'
THEN
CASE WHEN fms1.currency != 'EUR'
THEN fms1.Amount * fms1.Rate
ELSE ISNULL(fms1.Amount, 0) END
ELSE 0 END) fmsRelationAmount,
SUM(
CASE WHEN fmsAir1.currency != 'EUR'
THEN fmsAir1.Amount * fmsAir1.Rate
ELSE ISNULL(fmsAir1.Amount, 0) END) fmsAirTotalAmount,
SUM(
CASE WHEN fmsProjects1.relationcode = 'SHIP02'
THEN
CASE WHEN fmsProjects1.currency != 'EUR'
THEN fmsProjects1.Amount * fmsAir1.Rate
ELSE ISNULL(fmsProjects1.Amount, 0) END
ELSE 0 END) fmsAirRelationAmount,
SUM(
CASE WHEN fmsProjects1.currency != 'EUR'
THEN fmsProjects1.Amount * fmsAir1.Rate
ELSE ISNULL(fmsProjects1.Amount, 0) END) fmsProjectsTotalAmount,
SUM(
CASE WHEN fmsProjects1.relationcode = 'SHIP02'
THEN
CASE WHEN fmsProjects1.currency != 'EUR'
THEN fmsProjects1.Amount * fmsProjects1.Rate
ELSE ISNULL(fmsProjects1.Amount, 0) END
ELSE 0 END) fmsProjectsRelationAmount
FROM [fms].[dbo].[file] f
LEFT JOIN [fms].[dbo].[outgoinginvoiceline] fms1 ON
fms1.filenumber = CONVERT(NVARCHAR, f.filenumber)
LEFT JOIN [fmsAir].[dbo].[outgoinginvoiceline] fmsAir1 ON
fmsAir1.filenumber = CONVERT(NVARCHAR, f.filenumber)
LEFT JOIN [fmsProjects].[dbo].[outgoinginvoiceline] fmsProjects1 ON
fmsProjects1.filenumber = CONVERT(NVARCHAR, f.filenumber)
) a
现在我想打印这个 SELECT 语句的输出。但是当我这样做时:
print '开票的总金额:' + CONVERT(nvarchar, fmsTotalAmount) + '为此关系的€' print '开票的总金额:' + CONVERT(nvarchar, fmsTotalRelationAmount) + '€ 总计'
但后来我收到以下错误:
在此上下文中不允许使用名称“fmsTotalAmount”。有效表达式是常量、常量表达式和(在某些情况下)变量。不允许使用列名。
在此上下文中不允许使用名称“fmsTotalRelationAmount”。有效表达式是常量、常量表达式和(在某些情况下)变量。不允许使用列名。
在印刷品上。如何从中获取值到变量中?而不是将其作为一行返回。我需要变量。