select (count(job) + job) from AceData group by job ??

select (count(job) + job)  from AceData  group by job

using ms sql server

the above not working

want to show,

25 myJob
30 otherjob
01 badjob
goodkAsked:
Who is Participating?
 
awking00Connect With a Mentor Commented:
select job, count(*) cnt from AceDate group by job
will give you two columns, if you want them in one, then

select cast(cnt as char) +  ' ' + job as countjobs from
(select job, count(*) cnt from AceDate group by job)
0
 
Pratima PharandeConnect With a Mentor Commented:
you mean to say uou need to show job name also

try tghis

select Cast(count(job) as varchar) + '  ' + job  from AceData  group by job
0
 
goodkAuthor Commented:
I've requested that this question be deleted for the following reason:

resolved used str() to convert
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
RehanYousafConnect With a Mentor Commented:
I dont think using STR function is a good idea unless you want fixed length

I would go with pratima's solution
0
 
goodkAuthor Commented:
I tried this, should this be ok?  The results looks fine
Select (type +' ('+ ltrim(str(count(type))) +')' ) as xtest from AceData group by type
0
 
goodkAuthor Commented:
thanks
0
 
RehanYousafCommented:
Yes that will work but why use to functions when you can get away with one

In programming trick is to make things simple not complicated

Select (type +' ('+ convert(varchar,count(type)) +')' )

Open in new window

0
 
goodkAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.