Return All Records When a Query Parameter Is Blank

Database
Enthusiast

Return All Records When a Query Parameter Is Blank

Dear all,

I want a query that Return All Records When a Query Parameter Is Blank and when I pass perameter is give me only records for this perameter.

I have done as below but is not working properly.

(When I pass perameter it work fine but When I pass nothing It's give me no records)

SELECT * FROM Table1

where (Product_Sub_Group_Code like '?NameStart'  and  Product_Sub_Group_Code is  not null)

or (Product_Sub_Group_Code is   null)

Please any help!

THanks

Vinay

1 REPLY
Fan

Re: Return All Records When a Query Parameter Is Blank

Hi,

There's probably a better way but this works for me:

SELECT * FROM dbc.tables

where (tablename = '?NameStart') OR (substr('?NameStart',1,1)= '?')

It does ask for the parameter twice though, can't see a way around that yet.

Lee