views:

1173

answers:

3

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

Example:

PRINT 
    SELECT SUM(Amount) FROM Expense
A: 
set @n = (select sum(Amount) from Expense)
print 'n=' + @n
jspcal
+1  A: 

Its not possible. What you can do, though, is change where the query results will output.

Options are:

Text File Grid

Gabriel McAdams
+2  A: 

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).

Mark Brittingham