SQL Server PRINT SELECT(打印选择查询结果)? [英] SQL Server PRINT SELECT (Print a select query result)?

查看:559
本文介绍了SQL Server PRINT SELECT(打印选择查询结果)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印选定的值,这可能吗?

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

示例:

PRINT 
    SELECT SUM(Amount) FROM Expense

推荐答案

您知道,也许有一种更简单的方法,但首先想到的是:

You know, there might be an easier way but the first thing that pops to mind is:

Declare @SumVal int;
Select @SumVal=Sum(Amount) From Expense;
Print @SumVal;

您当然可以通过这种方式从表格中打印任意数量的字段.当然,如果要打印返回多行查询的所有结果,只需将输出适当地定向(例如,定向到文本)即可.

You can, of course, print any number of fields from the table in this way. Of course, if you want to print all of the results from a query that returns multiple rows, you'd just direct your output appropriately (e.g. to Text).

这篇关于SQL Server PRINT SELECT(打印选择查询结果)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆