Note that there are some explanatory texts on larger screens.

plurals
  1. POnot able to retrieve if the table column has null value
    primarykey
    data
    text
    <p>I have stored procedure to find customer, its working fine. If <code>Customer_City_Name</code> is null in the table then I am not able to retrieve the row. SP fails . how to do this I have to get result even if <code>Customer_City_Name</code> or <code>Customer_Country_Code</code> <code>IS NULL</code> </p> <pre><code>EXEC findCustomer null,'%',null,null, </code></pre> <p>SP code:</p> <pre><code>CREATE PROCEDURE findCustomer @customerNumber NVARCHAR(100), @customerNamePattern NVARCHAR(35), @customerCityNamePattern NVARCHAR(35), @customerCountryCode NVARCHAR(5) AS BEGIN DECLARE @SQL NVARCHAR(4000) SET @SQL = ' SELECT c.Customer_Number, c.Customer_Name, c.Postal_Address_Identifier, c.Customer_Street_Or_Road_Name, c.Customer_City_Name, c.Customer_Territory_Code, c.Customer_Postal_Code, c.Customer_Country_Code, c.Telephone_Number, c.Mobile_Telephone_Number, c.Fax_Number, c.Email_Address FROM Customer c WHERE c.Customer_Number LIKE ' + CASE WHEN @customerNumber IS NOT NULL THEN '''' + @customerNumber + '''' ELSE 'c.Customer_Number' END + ' AND c.Customer_Name LIKE ' + CASE WHEN @customerNamePattern IS NOT NULL THEN '''' + @customerNamePattern + '''' ELSE 'c.Customer_Name' END + ' AND c.Customer_City_Name LIKE ' + CASE WHEN @customerCityNamePattern IS NOT NULL THEN '''' +@customerCityNamePattern + '''' ELSE 'c.Customer_City_Name' END + ' AND c.Customer_Country_Code LIKE ' + CASE WHEN @customerCountryCode IS NOT NULL THEN '''' +@customerCountryCode + '''' ELSE 'c.Customer_Country_Code' END EXEC sp_executesql @SQL </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload