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
MikeM670Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
Something like this perhaps:
select 'Count: ' + cast(count(*) as varchar(10))
from Person.....
0
Mark WillsTopic AdvisorCommented:
select 'Count : ' + ltrim(count(*)) from Person

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeM670Author Commented:
Both solutions worked but Marks was more elegant.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Anthony PerkinsCommented:
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()
0
Mark WillsTopic AdvisorCommented:
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
0
Anthony PerkinsCommented:
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?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.