Link to home
Start Free TrialLog in
Avatar of JoelVogt
JoelVogt

asked on

Microsoft SQL Server 2000 Query Question

Hello!

I have a customer who has a book store online.  The books are arranged in the category trees such as:

Theology & History > Greco Roman Studies > Ancient Philosophy
Theology & History > Medieval > Manuscript Studies
Theology & History > Medieval > Byzantine Studies

They wanted it so that a book would be displayed in the category it was assigned to, plus any categories above.  Originally a book was only to fall into one category, but several years later, that has changed and they are now adding books to multiple categories and multiple book entries are showing up on the top level pages.

For example, if a book is in Ancient Philosophy and Manuscript Studies, it will show up twice under Theology & History.  

I currently have the books in a table:

Books2

Important Fields:
ID: Unique ID, Primary Key
manam: Authors Name
Approval: Is the book approved for display (1=yes, 0=no)
CataDate: Catalog Date, If the CataDate is less than today, then display the book
Private: Is the book Private (1=yes and dont display and 0=no and display)

BCJoin

Important Fields
BookID: Books2.ID
CatID: The ID of the Category in the Category Tree

SQL is not my strong suit, I know enough to get by, but Im assuming that there is a way to pull all the books in the top category and all sub-categories while being able to sort them by the Authors Name and then the Book Title.

Here is the page in question for reference:

https://secure4.visionsweb.com/loomebooks/Store5.cfm?DCatID=194

And my SQL Code is below.

Thank you for your help!
Joel
Select *
From Books2, BCJoin
Where (BCJoin.CatID = 265 or BCJoin.CatID = 278 or BCJoin.CatID = 285 or BCJoin.CatID = 286 or BCJoin.CatID = 358 or BCJoin.CatID = 359 or BCJoin.CatID = 284 or BCJoin.CatID = 279 or BCJoin.CatID = 217 or BCJoin.CatID = 220 or BCJoin.CatID = 275) and Books2.ID = BCJoin.BookID and Books2.Approval = 1 and (Books2.CataDate <{d '2009-07-07'} or Books2.CataDate is Null) and (Dead is Null or Dead = 0) and Private = 0
Order by Books2.MANAM, Books2.TNAM

Open in new window

Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

You're better off creating a mapping table.

Columns:
CatID  MapsTo

Example:
Midieval 101
Manuscript Studies 102
Byzantine Studies 103

Entries in table
102 101
103 101


when a book is searched for in midieval (101) find any entries in the table that map to it (select CatID from mapping where mapsto=101)

Then get books for those categories as well.
ASKER CERTIFIED SOLUTION
Avatar of shoppedude
shoppedude

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JoelVogt
JoelVogt

ASKER

Changing it to:

Select distinct Books2.*

Did it, but I had to change two field from text to varchar 5000 fields instead.

Thank you!
Thank you very much!!!  I appreciate your help!!!