如何处理空值是选择哪里条件? [英] How handle Empty value is select where condition?
本文介绍了如何处理空值是选择哪里条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有网页表格它有搜索条件,它有2个文本框,
现在我该怎么办?通过在一个文本框中输入值来开发一个选择查询以检索数据,而其他文本框仍然为空
ie
Hello Everyone,
I have web form it has a search criteria, It has 2 text box,
Now How can I develop a select query to retrieve data by entering value in only one text box and other remains empty
i.e.
my table is
create table StudentName
(id int,
fname nvarhcar(50),
lname nvarchar(50)
)
推荐答案
如果你有NULL
中的值数据库,您还可以使用如下变体:
If you haveNULL
values in the database, you could also use a variation like:
SELECT
...
FROM StudentName sn
WHERE COALESCE(fname , '') LIKE '%' + @fname + '%'
AND COALESCE(lname, '') LIKE '%' + @fname + '%'
要定义查询的值,请使用SqlParameter [ ^ ]
如果要保持单向/查询处理,可以这样做:
If you want to keep a single way/query to handle, it can be done like this in a way:
SELECT
ID,
Name,
Country
FROM
MyTable
WHERE
Name LIKE '%'+@NameValue+'%'
AND
Country LIKE '%'+@CountryValue+'%'
或者写一个SP并在那里处理参数值。检查它是否为空或NULL并相应处理。从SP返回结果。
OR write a SP and handle the parameter value there. Check if it is empty or NULL and handle accordingly. Return the result from SP.
这篇关于如何处理空值是选择哪里条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文