Arama için kullanmam ve tüm değerleri almayı planladığım bir yordamım var.WHERE yan tümcesinde LIKE ve NULL SQL
Senaryo: geçirilen parametre ise NULL
masanın tüm değerleri döndürmelidir ve geçirilen parametre NULL
değilse bu gibi olduğu duruma göre değerler döndürmelidir.
// Sorgu: i NULL
varsayılır beri yürütmek SQL
tarafından string
olarak, bu yüzden where
fıkrada yazmak gerektiğini istenilen çıktıyı almak için yukarıdaki sorguda
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 '%'[email protected]+'%'
hiçbir değerleri döndürür ?
ALTER procedure [dbo].[usp_GetAllCustomerDetails]
(
@Keyword nvarchar(20) = null
)
As
Begin
SET @Keyword = coalesce(@Keyword,'')
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 '%'[email protected]+'%'
Olası kopya https://stackoverflow.com/questions/3924400/like-does-not-accept-null-value –