Solved

query loop

Posted on 2011-09-05
5
339 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 125 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 125 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 125 total points
ID: 36483781
0
 
LVL 10

Assisted Solution

by:plummet
plummet earned 125 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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