Write a sql for searching with multiple conditions

Posted by Lu Lu on Stack Overflow See other posts from Stack Overflow or by Lu Lu
Published on 2010-05-05T03:47:16Z Indexed on 2010/05/05 3:58 UTC
Read the original article Hit count: 306

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server