Solved

query loop

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard 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 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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

816 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

11 Experts available now in Live!

Get 1:1 Help Now