SQL Returning record position / count together

Hi,

I want to return a record position and count as a varchar.  I can calculate the position by counting the records less that the current record, and the count by simply counting the records, but how i can i do this in 1 query and have them in seperate fields:

eg:      Pos      Count
      2      10

THere is also another criteria that needs to be applied im not sure if it will complicate issues. EG count will be SELECT COUNT(id) FROM tablename WHERE type=1;

Thanks,
Michael
LVL 1
Xavior2K3Asked:
Who is Participating?
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.

paeloCommented:
SELECT y.pkfld, (SELECT COUNT(*) FROM dbo.yourtable WHERE pkfld<=y.pkfld) AS pos
FROM dbo.yourtable y
WHERE y.type=1


-Paul.
0
LowfatspreadCommented:
do you mean

select id,count(*)
from table
where type = 1
group by id
order by id

?

or
select pos,num as [count]
from (
Select a.id, Num,count(*) as pos
from Table as A
Inner Join (
select id,count(*) as Num
from table
where type = 1
group by id
) as b
on A.id <=b.id
group by a.id,num
) as c
order by pos

?
 
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
LowfatspreadCommented:
sorry...

select convert(varchar(10),pos),convert(varchar(10),num) as [count]
from (
Select a.id, Num,count(*) as pos
from Table as A
Inner Join (
select id,count(*) as Num
from table
where type = 1
group by id
) as b
on A.id <=b.id
group by a.id,num
) as c
order by pos
0
Anthony PerkinsCommented:
For the record:  The questioner chose to ignore over a month ago, a  reminder for this abandoned question:
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21117933.html
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
Microsoft SQL Server

From novice to tech pro — start learning today.

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.