SQL Server PRINT SELECT (Print a select query result)?

前端 未结 10 1695
心在旅途
心在旅途 2020-12-25 09:37

I am trying to print a selected value, is this possible?

Example:

PRINT 
    SELECT SUM(Amount) FROM Expense
10条回答
  •  一整个雨季
    2020-12-25 10:11

    If you're OK with viewing it as XML:

    DECLARE @xmltmp xml = (SELECT * FROM table FOR XML AUTO)
    PRINT CONVERT(NVARCHAR(MAX), @xmltmp)
    

    While the OP's question as asked doesn't necessarily require this, it's useful if you got here looking to print multiple rows/columns (within reason).

提交回复
热议问题