Solved

query loop

Posted on 2011-09-05
5
297 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now