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
 SQL Server Development (2000)
 Categorizing data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-28 : 09:48:28
Per writes "I wonder if there's a smarter way to categorize data in ASP.NET, than the way I'm doing it in classic ASP.
I need to graphically show data in a categorized way, like this:

Category
   Product
   Product

Category
   Product
   Product
   Product

Category
   Product

Is there a smart SQL query that can help me do that??
I have 2 tables in SQL server, one called Categories and the other Products.


Categories table
----------------
PK_ID int (primary key, identity)
Name nvarchar (50)

Products table
----------------
PK_ID int (prim. key, identity)
FK_CatId int (the PK_ID of Categories table)
Name nvarchar (50)



I normally pull all of the categories out and store them in array. Then I loop through that array and for each element in it, I'd run
a SQL-query to get all of the products associated with that element.


' Pseudo VBScript-code
' Select all categories an put them in an array and loop through it.

catArray(pkid,name) = SELECT PK_ID,Name FROM Categories
FOR i = lBound(catArray) to uBound(catArray)
response.write catArray(name,i)

proArray(name) = SELECT name FROM Products WHERE FK_CatId = catArray(pkid,i)
FOR p = lbound(proArray) to uBound(proArray)
response.write "nbsp;nbsp;nbsp;" & proArray(name,p)
NEXT
NEXT


I know that this isn't the most beautifull way to do it, so can you please help me??"

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-06-28 : 11:03:40
Have you considered an structure where the database returned an XML fragment and the asp.net front end transformed it for display?

Jonathan Boott, MCDBA
Go to Top of Page

pehim
Starting Member

6 Posts

Posted - 2002-07-08 : 03:29:48
Yes, I've done that and it works perfectly...
However, it would be much more nice if I could do it bypassing the xml-transformation... I've tried with some DataRelations, but it didn't work out :-(

Go to Top of Page
   

- Advertisement -