|
-
Mar 8th, 2012, 11:06 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to select multiple filter values of the same column in sqlce?
Hey guys, im now trying to do a sort of selecting with multiple filters, like this for example:
Code:
sqlcecommand.commandtext="SELECT Name FROM Students WHERE ID=@ID;
sqlcecommand.parameters.addwithvalue("@ID",string[0])
sqlcecommand.parameters.addwithvalue("@ID",string[1])
sqlcecommand.parameters.addwithvalue("@ID",string[2])
sqlcecommand.parameters.addwithvalue("@ID",string[3])
and so on....
As in the example what i want is to be able to make a select and filter with more than one value on the same column so if i type id=1 and id=2 only the fields containing id1 and id2 will be shown, please note that the < or > filters wont work here because if i want for example: id=5 id =8 id =10 it will return everything between 5 and 10 rather than only returning whats with 5 whats with 8 and whats with 10, i hope i explained myself.
Is what i want possible in one commandtext?
Thanks in advance!
-
Mar 8th, 2012, 07:50 PM
#2
Re: How to select multiple filter values of the same column in sqlce?
Obviously one parameter can't have multiple values. If you want multiple values then you need multiple parameters. Testing one column for multiple values is exactly the same as testing multiple columns. For multiple columns you have multiple criteria, each in the form (COLUMN OPERATOR VALUE), separated by AND and/or OR operators. This is exactly the same. You'll just have the same column name in each criterion but, other than that, it's exactly the same.
You can also use the IN operator with a list of values, which SQL Server supports and I think CE does too, e.g.
sql Code:
WHERE SomeColumn IN (Value1, ..., ValueN)
Again, if you're using parameters for the values then you need one parameter per value.
-
Mar 9th, 2012, 07:21 AM
#3
Thread Starter
Hyperactive Member
Re: How to select multiple filter values of the same column in sqlce?
 Originally Posted by jmcilhinney
Obviously one parameter can't have multiple values. If you want multiple values then you need multiple parameters. Testing one column for multiple values is exactly the same as testing multiple columns. For multiple columns you have multiple criteria, each in the form (COLUMN OPERATOR VALUE), separated by AND and/or OR operators. This is exactly the same. You'll just have the same column name in each criterion but, other than that, it's exactly the same.
You can also use the IN operator with a list of values, which SQL Server supports and I think CE does too, e.g.
sql Code:
WHERE SomeColumn IN (Value1, ..., ValueN)
Again, if you're using parameters for the values then you need one parameter per value.
Thank you again! (IN) works like a charm ^^
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|