Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to write for loop in a query

Author  Topic 

anilr499
Starting Member

18 Posts

Posted - 2012-07-18 : 22:32:09
hi,

i have query like

SELECT * FROM emp WHERE C_MAIN='" & sNAME & "'

here sNAME is the name which i select from dropdownlist..

so,now my question is...

how can keep a for loop in this query so that i can pass

multiple sname's(using list box) through this query

something like this

eg: SELECT * FROM emp WHERE C_MAIN='" & sNAME & "' or c_main='" & sNAME & "' or C_MAIN='" & sNAME & "'..............

can somebody help me in writing this query with loop

thank you.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-07-18 : 23:14:18
refer to http://www.sommarskog.se/arrays-in-sql-2005.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-19 : 00:01:41
no need of loop. just pass them as a list as article says

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

anilr499
Starting Member

18 Posts

Posted - 2012-07-19 : 00:29:59
quote:
Originally posted by visakh16

no need of loop. just pass them as a list as article says

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/







hi can u suggest me some examples..
in my requirement i may select 'n' number of names from listbox...
then how can i write query ...
thank you
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-07-19 : 00:33:32
quote:
Originally posted by anilr499

quote:
Originally posted by visakh16

no need of loop. just pass them as a list as article says

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




hi can u suggest me some examples..
in my requirement i may select 'n' number of names from listbox...
then how can i write query ...
thank you



Have you take a look at the link that i posted ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -