Click here to Skip to main content
14,865,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I have a table student.
C#
select * from Table1 


ID	Name	Course	GPA
1	John	Maths	3
1	John	Science	3
1	John	French	3
2	bob	French	2
2	bob	Maths	3
3	Mike	Science	3
3	Mike	Law	4
4	Chelsa	Law	3
4	Chelsa	Maths	2
4	Chelsa	Science	1
5	Cloe	English	2
5	Cloe	French	3
5	Cloe	Chineese	3


Now I want to write a query that get all the student info based on course they took.
For example

select * from Table1 where Course in ('Science','Maths')


That is an inline query ... Now I want to use parameterized query for the same.
I only took two courses as example. But what if I have multiple?

What I have tried:

Here is what I have tried...
I have got all the checked subjects into a string in vb.net
VB.NET
Dim strCoursecode As New List(Of String)


C#
For Each dr As DataRow In dtCoursecodes.Rows
      strCoursecode.Add(dr("Course"))
If strCoursecode.Count > 0 Then strCoursecode.Add(String.Empty)

String.Join(vbTab, strCoursecode.ToArray)


My Stored procedure will pass parameters like 'Maths Science'

@TEST is my parameter
SELECT * FROM  TABLE1 WHERE COURSE IN ( @TEST )


Now can anyone help me with the query on how to pass parameterized query for IN clause
Posted
Updated 9-Nov-16 3:55am

1 solution

   
Comments
sudevsu 9-Nov-16 10:02am
   
I don't think you have seen my tags. It is for Db2. If I know for Db2 I can write for MySQL. All the links you have in solution are already referred before posting the question. They don't help for Db2. passing with comma separator is my thought too but query should have something like this in IN clause('A','B','C'). ('A,B,C') doesn't work on IN. It works on FIND_IN_SET function MYSQl

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900