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.
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 TABLEIF 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 ,TitleFROM bookwhere [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 TITLE103839-2007 CPC Ardmore072148-2008 YBM Longview-Marshall100133-2008 CBC Melbourne Palm Bay100132-2008 TMM Cocoa-Titusville Area068029-2007 AMM Connecticut ShoreThank 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, Titlefrom bookorder by ID KH[spoiler]Time is always against us[/spoiler] |
 |
|
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? |
 |
|
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 TABLEIF OBJECT_ID ('tempdb..#Book')IS NOT NULLDROP TABLE #BookCREATE TABLE #Book (SORTID int Identity(1,1),[ID] varchar(12) ,Publisher varchar(30),Title varchar(30))INSERT INTO #BookSELECT [ID] ,Pub,TitleFROM bookwhere [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. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-12 : 01:36:40
|
[code]INSERT INTO #BookSELECT [ID] ,Pub ,TitleFROM book b INNER JOIN dbo.fnParseList('103839-2007','072148-2008','100133-2008','100132-2008','068029-2007') lWHERE b.[ID] = l.Data ORDER BY l.RowID[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
KENI
Starting Member
6 Posts |
Posted - 2008-08-12 : 02:32:13
|
Thank you..Khtan |
 |
|
|
|
|
|
|