Multi-condition inquiry in SQL2000

xiaoxiao2021-03-06  138

That is, there are multiple conditions, but it is not necessarily the query for every condition.

For example, there is a structure of table a as follows

ID INT number

Name varchar (10) name

Sex bit gender

If you want to build a stored procedure, query this table, you have to do this to 3 to 3 to meet this particular condition, we can design:

Alter procedure dbo.newselectcommand (@ID int, @ name nvarchar (18), @ sex bit) Asset NoCount ON; SELECT ID, NAME, SEX from a where (id = @ id or @id is null) and (name = @ Name or @name is null) and (sex = @ sex or @sex is null)

In this way, it can be very convenient to do so many cases. Don't construct query strings, which is not safe. Trouble AJQC blog

转载请注明原文地址:https://www.9cbs.com/read-127719.html

New Post(0)