?
Solved

query loop

Posted on 2011-09-05
5
Medium Priority
?
343 Views
Last Modified: 2012-08-14
hey guys, how can i loop through my tables

i have two Tables: foodtypes and pretoria

in my foodtypes table i have this coloums: id type

in my pretoria coloums: id, foodtypes, name

now i am doing a search to find the restaurant with my foodtypes

in my pretoria table in foodtypes coloums i store a list of food type like this

buffet,indian

now i want to do a loop to split the string and check if the string equals the user selection?
0
Comment
Question by:JCWEBHOST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 500 total points
ID: 36483307
You should use cursors on T-SQL. Please see this link:

http://www.jackdonnell.com/articles/SQL_CURSOR.htm
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36483323
Keep foodtypes  ID as PRIMARY key. Refer this ID in the table pretoria as a REFERENCE key.

Search can be done using JOIN.

SELECT [col]
from foodtypes  ft
INNER JOIN pretoria  P
ON ft.ID = P.foodtypeid
where [your search condition].

0
 
LVL 16

Assisted Solution

by:Easwaran Paramasivam
Easwaran Paramasivam earned 500 total points
ID: 36483330
Still you want to do perform loop use cursor.
http://www.jackdonnell.com/articles/SQL_CURSOR.htm

Try to use CTE if it suite your needs
http://msdn.microsoft.com/en-us/library/ms175972.aspx
0
 
LVL 9

Assisted Solution

by:mimran18
mimran18 earned 500 total points
ID: 36483781
0
 
LVL 10

Assisted Solution

by:plummet
plummet earned 500 total points
ID: 36483807
Hi,

I recommend you never use cursors, they are slow and inefficient. There are almost always other ways to retrieve the information you need.

Do you want to search for more than one value in the foodtypes column, or just one?

Regards
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

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