Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pull info out of a specific field?

Status
Not open for further replies.

mGis

Programmer
Mar 22, 2001
29
US
I have a field that is broken into subset's of data seperated by comma's.
table looks like:
tblAnswers
Ans_QuestProdID = Relates to Product
Ans_Quest = Relates to Question Number
Ans_String_Val = Is the answer to the Question
Ans_UserID = User ID

This is a Data Field that is filled(with Radio Boxes) by users on a web site.

Ans_QuestProdID=345 relates to pet's.
Ans_Quest=6 ask what types of pets they own.
If the Choices are Cat, Dog, Bird, Other, None
The Data Field will look like :
If they own only a
Cat: Ans_String_Val = 'on,,,,'
Dog: Ans_String_Val = ',on,,,'
Bird: Ans_String_Val = ',,on,,'
Other: Ans_String_Val = ',,,on,'
None: Ans_String_Val = ',,,,on'
Say if they own a Cat and a Dog
Cat & Dog: Ans_String_Val = 'on,on,,,' Ect., Ect.

1.Is there a way to run a query that looks like

Ans_UserID CAT DOG BIRD OTHER NONE
1 YES YES NO NO NO
2 NO NO NO NO YES
3 NO YES NO YES NO

2.How can I ask for a list of users that own Dogs
SELECT Ans_UserID FROM tblAnswers WHERE
Ans_QuestProdID=345 AND
Ans_Quest=6 AND
Ans_String_Val=',on,,,'

BUT this is only good if they own only a dog! I need a complete list of dog owners, whether or not they own other pets.

I have read through many, many books but to no avail, so if anybody can help, it would be greatly appreciated.

Thanks, Michael
Sorry for such a long post, but wanted to completely explain it.
 
For starters, I would change the structure of your table to have a one-character column for dog, one for cat, etc.

Assuming this isn't possible, the actual answer to how to do what you want depends a greate deal on the RDBMS you are using. Let us know this information and we can press on from there.
 
Unfortunately, I'm not able to change the Dbase,
It has a structure of 45 tables, including virtul. It funtions great, but since I'm relativly new to SQL, I'm having trouble retrieving the info I need.

Dbase is running on SQL Server 7.0.

Thanks, Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top