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

goodk
goodk used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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

Author

Commented:
I've requested that this question be deleted for the following reason:

resolved used str() to convert
I dont think using STR function is a good idea unless you want fixed length

I would go with pratima's solution
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Information Technology Specialist
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)

Author

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

Author

Commented:
thanks
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

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial