Write a sql for searching with multiple conditions
- by Lu Lu
Hello everyone,
I have a table Student with 2 fields:
Name: nvarchar(256)
Age: int
User will use a WinForm application to input a Name and a Age for searching.
If inputted Name is empty, sql will not query Name field.
If inputted Age is 0, sql will not query Age field.
If Name is Null and inputted Name is empty - record is matched. If Name is Null and inputted Name is not empty - record is not matched. And also similar for Age field.
My problem is that how to write a sql like this.
P/S: I use SQL Server 2005.
Please help me. Thanks.