C# .NET - write multiple conditions in a single sql query

Asked By Priyanka on 22-Jun-13 01:38 AM
I am new to sql. I am in a situation where i have to put three different conditions in a single query. If any of the below conditions retreive records MessageBox should be shown "Records Retreived" else "Nothing Retreived".

Condition 1 : Select Name, Age from Table1 where Class = '1st' and Date between #"+1st_Date.ToString() +"# and #"+2nd_Date.ToString() +"# .

Condition 2 : Select Name, Age from Table1 where Class = '2nd' and Date between #"+1st_Date.ToString() +"# and #"+2nd_Date.ToString() +"# .

Condition 3 : Select Name, Age from Table1 where Class = '2nd' and Date > #"+1st_Date.ToString()+"# and Date  < #"+2nd_Date.ToString()+"#

My question is how to write these three conditions in a single query. Hope you understand my question. I am searching for the answer for very long but all in vain. I will be very thankful of yours.
Reena Jain replied to Priyanka on 22-Jun-13 01:43 AM
Hi,

You can use "in" available in sql server like this

Select Name, Age from Table1 where Class  in ('1st', '2nd') and Date between #"+1st_Date.ToString() +"# and #"+2nd_Date.ToString() +"# .

or you can use "and" "or" operator like this

Select Name, Age from Table1 where Class ='1st' or class='2nd' and Date between #"+1st_Date.ToString() +"# and #"+2nd_Date.ToString() +"# .

Hope this will help you