Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SORTING

Author  Topic 

KENI
Starting Member

6 Posts

Posted - 2008-08-11 : 23:30:50
I have a table named "Book," and it has so many data that is stored in it. However, I only want to view 5 ID's only.

Could you please tell me how I can sort them by ID?

Below is the sample of the table that I am referring to.

SAMPLE TABLE

IF OBJECT_ID ('tempdb..#Book')IS NOT NULL
DROP TABLE #Book
CREATE TABLE #Book (
SORTID int Identity(1,1)
,[ID] varchar(12)
,Publisher varchar(30)
,Title varchar(30))

INSERT INTO #Book
SELECT
[ID]
,Pub
,Title
FROM book
where [ID]in ('103839-2007','072148-2008','100133-2008','100132-2008','068029-2007')


THE DESIRED OUTPUT THAT I WOULD LIKE TO HAVE IS THIS:

ID PUB TITLE
103839-2007 CPC Ardmore
072148-2008 YBM Longview-Marshall
100133-2008 CBC Melbourne Palm Bay
100132-2008 TMM Cocoa-Titusville Area
068029-2007 AMM Connecticut Shore

Thank you for your help...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-11 : 23:48:51
Don't quite understand your requirement.

You mean this ?
select top 5 [ID], Pub, Title
from book
order by ID



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-12 : 00:33:59
Your sample data doesnt show results sorted on any order. can you explain on what basis you want to order?
Go to Top of Page

KENI
Starting Member

6 Posts

Posted - 2008-08-12 : 01:26:29
What I was trying to say is that from the sample table below, in the part that's highlighted in red, that's the order of the items that I would like to have...where in "103839-2007" is the first in order and the "068029-2007" is the last in order.

SAMPLE TABLE

IF OBJECT_ID ('tempdb..#Book')IS NOT NULL
DROP TABLE #Book
CREATE TABLE #Book (
SORTID int Identity(1,1)
,[ID] varchar(12)
,Publisher varchar(30)
,Title varchar(30))

INSERT INTO #Book
SELECT
[ID]
,Pub
,Title
FROM book
where [ID]in ('103839-2007','072148-2008','100133-2008','100132-2008','068029-2007')




Please refer to the "Desired Output" that I would like to have.

Thanks for your inputs.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-12 : 01:36:40
[code]INSERT INTO #Book
SELECT
[ID]
,Pub
,Title
FROM book b
INNER JOIN dbo.fnParseList('103839-2007','072148-2008','100133-2008','100132-2008','068029-2007') l
WHERE b.[ID] = l.Data
ORDER BY l.RowID[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

KENI
Starting Member

6 Posts

Posted - 2008-08-12 : 02:32:13
Thank you..Khtan
Go to Top of Page
   

- Advertisement -