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

前端 未结 10 1692
心在旅途
心在旅途 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:03

    If you wish (like me) to have results containing mulitple rows of various SELECT queries "labelled" and can't manage this within the constraints of the PRINT statement in concert with the Messages tab you could turn it around and simply add messages to the Results tab per the below:

    SELECT 'Results from scenario 1'
    SELECT
        *
    FROM tblSample
    

提交回复
热议问题