Home All Groups Group Topic Archive Search About
Author
21 Jul 2006 6:16 PM
Aussie Rules
Hi all,

I select two cols from a table, but I want to add another column that is
just a number count.

For example, selecting the top ten selling books returns

Book A, ISBN
Book B, ISBN
Book C, ISBN

etc...

I want to in the my Stored Proc, just add a number that would make the
returned result

1,Book A, ISBN
2,Book B, ISBN
3,Book C, ISBN

How can I do this

Thanks

Author
21 Jul 2006 6:33 PM
Alejandro Mesa
SQL Server 2000

How to dynamically number rows in a SELECT Transact-SQL statement
http://support.microsoft.com/default.aspx?scid=kb;en-us;186133

SQL Server 2005

ROW_NUMBER (Transact-SQL) 
http://msdn2.microsoft.com/en-us/library/ms186734.aspx


AMB

Show quote
"Aussie Rules" wrote:

> Hi all,
>
> I select two cols from a table, but I want to add another column that is
> just a number count.
>
> For example, selecting the top ten selling books returns
>
> Book A, ISBN
> Book B, ISBN
> Book C, ISBN
>
> etc...
>
> I want to in the my Stored Proc, just add a number that would make the
> returned result
>
> 1,Book A, ISBN
> 2,Book B, ISBN
> 3,Book C, ISBN
>
> How can I do this
>
> Thanks
>
>
>
Author
22 Jul 2006 4:39 AM
sloan
declare @mytab table ( entryid int identity(1,1) , bookName varchar(12) ,
isbn varchar(12) )

INSERT INTO @mytab (bookName, isbn)
    select bn , isbn from dbo.BooksTable

--OR
INSERT INTO @mytab (bookName, isbn)
    values ( "ManualBook1" , "00000001)
INSERT INTO @mytab (bookName, isbn)
    values ( "ManualBook2" , "00000002)


Select entryid , bookName , isbn from @mytab

watch out!  this is good for smaller/medium recordsets.  but when you get
into the 100,000's , then you need to watch performance, or try a #temp
table.




Show quote
"Aussie Rules" <AussieRules@nospam.nospam> wrote in message
news:elhGpIPrGHA.3992@TK2MSFTNGP04.phx.gbl...
> Hi all,
>
> I select two cols from a table, but I want to add another column that is
> just a number count.
>
> For example, selecting the top ten selling books returns
>
> Book A, ISBN
> Book B, ISBN
> Book C, ISBN
>
> etc...
>
> I want to in the my Stored Proc, just add a number that would make the
> returned result
>
> 1,Book A, ISBN
> 2,Book B, ISBN
> 3,Book C, ISBN
>
> How can I do this
>
> Thanks
>
>

AddThis Social Bookmark Button