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
I need help in displaying a text Label and count on a single row.
select count(Name) as 'Count: '
from Person.....
Count: 12
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both solutions worked but Marks was more elegant.
Both solutions worked but Marks was more elegantYou 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
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?
select 'Count: ' + cast(count(*) as varchar(10))
from Person.....