-3

I have the following query:

SELECT sum(qty) AS TotalItems FROM Sales.OrderDetails;

And this returns

+------------+
| TotalItems |
+------------+
| 51317      |
+------------+

However, I want the output to read

+------------------------------+
| TotalItems                   |
+------------------------------+
| Total items ordered is 51317 |
+------------------------------+

How would I do this?

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82

2 Answers2

1

If you are using Sql Server 2008, then please try:

SELECT 'Total items ordered is ' + cast(sum(qty) as varchar(max)) AS TotalItems FROM Sales.OrderDetails;

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
  • Product specific answer to a question with no dbms specified. At least tell us which dbms this is for. – jarlh Feb 06 '18 at 21:10
  • edited........... – Eray Balkanli Feb 06 '18 at 21:12
  • Thank you very much for your help, it worked. I'm using Microsoft SQL Server Management Studio, and working with a database named: InsideTSQL2008 – Kurt Morrison Feb 06 '18 at 22:39
  • @KurtMorrison You are very welcome. I appreciate if you select the answer as the correct answer (by clicking the tick sign on the left), then other users who have similar problem and see your question find what to do easier – Eray Balkanli Feb 06 '18 at 23:49
1

Your database could be Oracle, and then you should try:

SELECT 'Total items ordered is ' || cast(sum(qty) as varchar(max)) AS TotalItems 
FROM Sales.OrderDetails
itsLex
  • 786
  • 1
  • 5
  • 13