Solved

Microsoft SQL Server 2000 Query Question

Posted on 2009-07-07
4
202 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:JoelVogt
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
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.
0
 
LVL 2

Accepted Solution

by:
shoppedude earned 500 total points
Comment Utility
Instead of using:

Select *

Have you tried using:

Select distinct Books2.*

-Lee
0
 

Author Comment

by:JoelVogt
Comment Utility
Changing it to:

Select distinct Books2.*

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

Thank you!
0
 

Author Closing Comment

by:JoelVogt
Comment Utility
Thank you very much!!!  I appreciate your help!!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Data lost in SQL server 23 94
SQL Query 18 80
What does this SQL mean? 7 41
VB Access SQL question 2 22
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now