Subject | Optional parameter in a select statement |
---|---|
Author | m_formigoni |
Post date | 2005-08-24T19:28:14Z |
Hi,
I have a table with the following fields:
IdLog integer not null PK,
User char(15) not null
Have also 1 index:
ix_User (User)
I'm trying to do a select where I can get the log records from a
specific User, or records of all user if '-1' is passed in the parameter.
I'm using the following select statement:
select * from LogTable
where ( (:User = cast('-1' as char(15))) or (User = :User))
It works but the plan I'm receiving from IBExperts is always NATURAL,
how can I write the same code IN ONE STATEMENT (without an IF) and use
the correct index?
I have a table with the following fields:
IdLog integer not null PK,
User char(15) not null
Have also 1 index:
ix_User (User)
I'm trying to do a select where I can get the log records from a
specific User, or records of all user if '-1' is passed in the parameter.
I'm using the following select statement:
select * from LogTable
where ( (:User = cast('-1' as char(15))) or (User = :User))
It works but the plan I'm receiving from IBExperts is always NATURAL,
how can I write the same code IN ONE STATEMENT (without an IF) and use
the correct index?