Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ranking ?

0 views
Skip to first unread message

Paulo

unread,
Oct 11, 2007, 9:06:40 AM10/11/07
to
Hi, I need to create a ranking column wich will be the row number... it is
the seller wich most sells...

Ranking Seller Sum
1 Paul 2.212,00
2 Robert 1.500,00
3 ....
....

I have already the sql, but I dont know how to do the ranking number
column...

Can you help me?

Using VS 2005 and Sql Server 2000

Thanks !


Just Me

unread,
Oct 11, 2007, 9:22:57 AM10/11/07
to
Your question is not clear. U say you have the sql so what is it you are
missing ?

Post the SQL you have and let us know what it is you need specifically


"Paulo" <prb...@uol.com.br> wrote in message
news:OXvdcfAD...@TK2MSFTNGP04.phx.gbl...

Paulo

unread,
Oct 11, 2007, 9:46:24 AM10/11/07
to
strSQL = "Select Empresa.NOME_EMPRESA,Vendedor.NOME_VENDEDOR
NOME_PROMOTOR,Sum(CONTRATO.VL_CREDITO) VL_CREDITO";
strSQL += " From Contrato,Empresa,Vendedor Where
CONTRATO.COD_EMPRESA=EMPRESA.COD_EMPRESA And ";
strSQL += "Contrato.COD_VENDEDOR=VENDEDOR.ID_VENDEDOR Group By
NOME_EMPRESA,NOME_VENDEDOR ";
strSQL += "Order by VL_CREDITO Desc";

Sorry, I forgot...

Is there any way creating on the sql the column ranking with the number?

Thanks

"Just Me" <news.microsoft.com> escreveu na mensagem
news:%23QXrUoA...@TK2MSFTNGP02.phx.gbl...

IfThenElse

unread,
Oct 11, 2007, 3:48:21 PM10/11/07
to
You can put the result from your select statement into a temp #table. your
temp table can have an Id column (ranknum) that is an auto increment to rank
your rows. or do it in code behind.

change the type I put nvarchar(100) Null on all

DECLARE @Empresa TABLE (
ranknum int IDENTITY(1,1) NOT NULL PRIMARY KEY,
NOME_EMPRESA nvarchar(100) NULL,
VendedorNOME_VENDEDOR nvarchar(100) NULL,
NOME_PROMOTORnvarchar(100) NULL,
sumVL_CREDITO nvarchar(100) NULL
)

then populate the temp table with the rank

INSERT into @Empresa (NOME_EMPRESA,VendedorNOME_VENDEDOR
,NOME_PROMOTORnvarchar,sumVL_CREDITO)
Select Empresa.NOME_EMPRESA,Vendedor.NOME_VENDEDOR
NOME_PROMOTOR,Sum(CONTRATO.VL_CREDITO) VL_CREDITO


From Contrato,Empresa,Vendedor Where
CONTRATO.COD_EMPRESA=EMPRESA.COD_EMPRESA And

Contrato.COD_VENDEDOR=VENDEDOR.ID_VENDEDOR Group By
NOME_EMPRESA,NOME_VENDEDOR
Order by VL_CREDITO Desc


Finally

select * from @Empresa


"Paulo" <prb...@uol.com.br> wrote in message

news:%238vgq1A...@TK2MSFTNGP04.phx.gbl...

rote

unread,
Oct 11, 2007, 9:08:19 PM10/11/07
to
I reckon there are many ways to do this
Patrick

"IfThenElse" <sql_ag...@hotmail.com> wrote in message
news:OkP2u%23DDIH...@TK2MSFTNGP05.phx.gbl...

IfThenElse

unread,
Oct 12, 2007, 12:47:18 PM10/12/07
to
yes many ways to do it.


"rote" <naija...@hotmail.com> wrote in message
news:uGbgixGD...@TK2MSFTNGP05.phx.gbl...

0 new messages