Hello everyone,
I am using SQL Server 2008 Enterprise with Windows Server 2008 Enterprise. I have a database table called "Book", which has many columns and three columns are important in this question, they are
- Author, varchar;
- Country, varchar;
- Domain, varchar.
I want to write a store procedure with the following logics, but I do not know how to write (because of complex query conditions), appreciate if anyone could write a sample for me?
Input parameter: p_author as varchar, p_country as varchar, and p_domain as varchar
Query conditions:
- if p_author is specified from input, then any row whose Author column LIKE %p_author% is satisfied with condition, if p_author is not specified from input every row is satisfied with this condition;
- if p_country is specified from input, then any row whose Country column = p_country is satisfied with condition, if p_country is not specified from input every row is satisfied with this condition;
- if p_domain is specified from input, then any row whose Domain column LIKE %p_domain% is satisfied, if p_domain is not specified from input every row is satisfied with this condition;
The results I want to return (must met with all following conditions):
- records met with either condition 1 or 2;
- records must meet with condition 3;
- return distinct rows.
For example, records which met with condition 1 and condition 3 are ok to return, and records which met with condition 2 and condition 3 are ok to return.
thanks in advance, George