我有一个商店程序,我计划用于搜索并获取所有值.
场景:
如果传递的参数是NULL它应该返回表的所有值,如果传递的参数不是,NULL它应该根据LIKE中的条件返回值.
//查询:
ALTER procedure [dbo].[usp_GetAllCustomerDetails]
(
@Keyword nvarchar(20) = null
)
As
Begin
Select CustomerId,CustomerName,CustomerTypeName,CustomerCode,CategoryName,CustomerMobile,CustomerEmail,CustomerAddress,CustomerCity,CustomerState,Pincode
from tblCustomerMaster CM
inner join dbo.tblCustomerTypeMaster CTM on CTM.CustomerTypeId = CM.CustomerType
inner join dbo.tblCategoryMaster CCM on CCM.CategoryId= CM.CustomerCategory
where CustomerName like '%'+@Keyword+'%'
Run Code Online (Sandbox Code Playgroud)
在上面的查询,当我执行,因为没有返回值NULL被假定为string通过SQL,所以我应该怎么了在写where子句,以获得所需的输出?
大多数SQL查询都没有对where子句进行数学运算.
将它们放在'where子句'上有什么问题?有任何性能问题吗?
例如:
SELECT*FROM Employee WHERE Salary*3 = 5000