Solved

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

Posted on 2012-12-27
8
230 Views
Last Modified: 2012-12-30
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
0
Comment
Question by:goodk
8 Comments
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 167 total points
ID: 38726121
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
 

Author Comment

by:goodk
ID: 38731559
I've requested that this question be deleted for the following reason:

resolved used str() to convert
0
 
LVL 5

Assisted Solution

by:RehanYousaf
RehanYousaf earned 166 total points
ID: 38726399
I dont think using STR function is a good idea unless you want fixed length

I would go with pratima's solution
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 32

Accepted Solution

by:
awking00 earned 167 total points
ID: 38727925
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
 

Author Comment

by:goodk
ID: 38731504
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
 

Author Closing Comment

by:goodk
ID: 38731560
thanks
0
 
LVL 5

Expert Comment

by:RehanYousaf
ID: 38731727
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
 

Author Comment

by:goodk
ID: 38731927
thanks
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql Server group by 10 42
sql help 2 45
Format Data Field - SQL 11 37
SQL Server group with two values 4 34
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question