Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have created an sql command with a where clause

where PLPRLC like @PLPRLC

and then the following parameter with option of all records

SQL
If ddlLocation.Text = "" Then
           daProductionMachines.SelectCommand.Parameters.Add(New SqlParameter("@PLPRLC", "%"))
       Else
           daProductionMachines.SelectCommand.Parameters.Add(New SqlParameter("@PLPRLC", ddlLocation.Text))
       End If


The problem is with the Null records which are not picked up in either case.
I want that in case of ddllocation.text="", all records should be fetched including Null.

Pls suggest.
Thanks
Atul
Posted

You need manipulate the query string. I assume your query something like this:

SQL
'SELECT * FROM members WHERE code LIKE @PLPRLC'


into

SQL
'SELECT * FROM members WHERE IFNULL(code, '') LIKE @PLPRLC'


Please refer to your SQL engine documentation. Query above should work in SQL Server or MySQL
 
Share this answer
 
Comments
atul sharma 5126 27-Feb-15 1:56am    
Thanks for the reply!
Message: 'IFNULL' is not recognized built-in function name

used is sql server 2012
Use the query like the following one...

select * from table_name where PLPRLC is null or PLPRLC like @PLPRLC
 
Share this answer
 
Comments
atul sharma 5126 27-Feb-15 1:58am    
Thanks for your reply dear!

But I have to specify the value of PLPRLC from a parameter based upon a drop down list.

If "All" is selected in the ddl then all records including Null are desired to be shown else only the selected ddl value records are to be shown.

Problem is when All is selected then Null records are not picked up..
Member 11484114 27-Feb-15 2:11am    
Check by using this query,

select * from table_name where (@PLPRLC='All') or (PLPRLC like @PLPRLC)

here, if u pass the parameter @PLPRLC as 'All', you will get all the records including
null or you will get only the records that is @PLPRLC (not null records also)
atul sharma 5126 27-Feb-15 2:33am    
Thanks a lot. It worked perfectly.
Check by using this query,

select * from table_name where (@PLPRLC='All') or (PLPRLC like @PLPRLC)

here, if u pass the parameter @PLPRLC as 'All', you will get all the records including
null or you will get only the records that is @PLPRLC (not null records also)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900