Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 ASP/SQL with CSV
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

lancepr
New Member

73 Posts

Posted - 05 March 2002 :  17:48:08  Show Profile
I am trying to select items out of my DB based on a querystring

in my DB I have an item like this

Name Description Category
test test 1,2,3,4
test2 test2 1,3,4
test3 test3 3,4


now I want to select all records that category = 3

Select name, description
from tbl_test
WHERE "&querystring&" IN (category)

here is my error
Syntax error converting the varchar value '26, 9, 15, 27 ' to a column of data type int.

How can I store/convert these CSV values in a type int?

Lance


ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 05 March 2002 :  18:00:43  Show Profile  Send ruirib a Yahoo! Message
quote:

Syntax error converting the varchar value '26, 9, 15, 27 ' to a column of data type int.



Where do these values come from, QueryString?

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

lancepr
New Member

73 Posts

Posted - 05 March 2002 :  18:14:30  Show Profile
No they are the actual values in My DB, sorry for the confusion

Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 05 March 2002 :  18:18:26  Show Profile
Is that ONE table you have in your database? If it is, I would suggest using two tables:

Table 1 fields: ID, Name, Description
Table 2 fields: Table1ID, Category

Then your example would look like:

ID Name Description
1 test test
2 test2 test2
3 test3 test3

Table1ID Category
1 1
1 2
1 3
1 4
2 1
2 3
2 4
3 3
3 4


It would be much easier to do what you want to do.

Nikkol
Go to Top of Page

Nathan
Help Moderator

USA
7664 Posts

Posted - 05 March 2002 :  18:42:05  Show Profile  Visit Nathan's Homepage
You could, in theory, store the values like you are and split them up into an array.

catagoriesArr = split(rs("Category"), " ,")

Then you would have to loop through the array looking for the value 3.

 Nathan Bales - Romans 15:13
---------------------------------

Snitz Exchange | Mod Resource


Edited by - Nathan on 05 March 2002 18:42:26
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 05 March 2002 :  18:42:58  Show Profile  Send ruirib a Yahoo! Message
lancepr

I would strongly recommend you to follow Nikkol's advice. The current structure of your DB violates the most elementary rule of database design, which is that each record (row) should have a single value in each column.

If you follow the structure recomended by Nikkol, you'll see that each Category has a single column value for each row. This means her recommended design follows this very basic DB design rule. Not following it will mean big difficulties to do whatever it is that you may want to do with your data (if you ever manage to do it at all).

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 05 March 2002 :  18:58:33  Show Profile
quote:

Not following it will mean big difficulties to do whatever it is that you may want to do with your data (if you ever manage to do it at all).

I think what ruirib is saying here is that say for example, you decide that category 3 no longer exists. You would have to do some pretty fancy footwork with your database to remove all of the 3s. If instead you have a separate table for category designation, you just perform a DELETE where the category is 3. Or better yet, you establish a cascading-delete integrity rule and just delete category 3 from yet another table (Category table) and voila all instances of category 3 magically disappear.

Nikkol
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07