Solved

query loop

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

'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 find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

16 Experts available now in Live!

Get 1:1 Help Now