Link to home
Start Free TrialLog in
Avatar of MikeM670
MikeM670

asked on

Display Label on Row as Count Total instead of as Column

MS SQL 2016

I need help in displaying a text Label and count on a single row.

select count(Name) as 'Count: '
from Person.....

Count: 12
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Something like this perhaps:
select 'Count: ' + cast(count(*) as varchar(10))
from Person.....
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeM670
MikeM670

ASKER

Both solutions worked but Marks was more elegant.
Both solutions worked but Marks was more elegant
You may want to look up the definition for COUNT (Transact-SQL).  In particular I would focus on the Return Type and the appropriate data types for  LTRIM()
LTRIM() will always render the result as a varchar or nvarchar. So long as it is not text,ntext or image.

https://docs.microsoft.com/en-us/sql/t-sql/functions/ltrim-transact-sql?view=sql-server-2017
LTRIM() will always render the result as a varchar or nvarchar.
I don't disagree.  That was not the point.

You can also do the following (try it):
Declare @Date datetime = getdate()
select ltrim(@Date)

The question is does it make sense? or more to the point, does it reach the "elegant" level?