| View previous topic :: View next topic |
| Author |
Message |
Ramtin Kazemi Guest
|
Posted: Thu Jul 08, 2004 10:07 pm Post subject: WHERE clause |
|
|
Hi
consider following SQL command :
SELECT * FROM MyTable WHERE KeyId = :KeyId
What should the value of parameter :KeyId be so that WHERE clause has no
effect?
(i.e. returns all records)
Thanks
Ramtin Kazemi
|
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Thu Jul 08, 2004 10:19 pm Post subject: Re: WHERE clause |
|
|
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote in
news:40edc596 (AT) newsgroups (DOT) borland.com:
| Quote: | What should the value of parameter :KeyId be so that WHERE clause has
no effect?
|
This changes according to DB server you're using.
You could have a where clause that is like
WHERE KeyId LIKE :KEY_ID
and settting the paramater to % if it is blank. This only works for
columns of type varchar/char.
With oracle you can do something like
WHERE KeyID = DECODE(:KEY_ID, 0, KeyId, :KEY_ID)
and set the parameter to 0 to get all the records. You should be able
to do similar things with other DBs.
Other than that you can have a stored procedure return a result set, or
rebuild the SQL statment everytime.
--
Iman
|
|
| Back to top |
|
 |
Ramtin Kazemi Guest
|
Posted: Fri Jul 09, 2004 10:48 am Post subject: Re: WHERE clause |
|
|
Hi Iman
I am using MS-SQL Server and column type is 'int' .
What should I do now?
Thank you
|
|
| Back to top |
|
 |
Paulo Juliano Horlle Guest
|
Posted: Fri Jul 09, 2004 12:22 pm Post subject: Re: WHERE clause |
|
|
Hi Ramtin!
You can start a trace with Profiler to get the command that Delphi is send
to SQLServer.
Regards,
Paulo Juliano Horlle
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote
| Quote: | Hi
consider following SQL command :
SELECT * FROM MyTable WHERE KeyId = :KeyId
What should the value of parameter :KeyId be so that WHERE clause has no
effect?
(i.e. returns all records)
Thanks
Ramtin Kazemi
|
|
|
| Back to top |
|
 |
Viatcheslav V. Vassiliev Guest
|
Posted: Fri Jul 09, 2004 12:23 pm Post subject: Re: WHERE clause |
|
|
To return all records, you should just remove WHERE.
SELECT * FROM MyTable
There is no way to specify parameter for KeyId and return all rows.
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> сообщил/сообщила в новостях
следующее: news:40edc596 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi
consider following SQL command :
SELECT * FROM MyTable WHERE KeyId = :KeyId
What should the value of parameter :KeyId be so that WHERE clause has no
effect?
(i.e. returns all records)
Thanks
Ramtin Kazemi
|
|
|
| Back to top |
|
 |
Paulo Juliano Horlle Guest
|
Posted: Fri Jul 09, 2004 12:30 pm Post subject: Re: WHERE clause |
|
|
I'm not understood before...
To get all records you can use this select:
select t.* from mytable t
where t.KeyID = isnull( :KeyID, t.KeyID)
Now, if you send a nul value to parameter, the statement compare with KeyID
field.
Regards,
Paulo Juliano Horlle
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote
| Quote: | Hi
consider following SQL command :
SELECT * FROM MyTable WHERE KeyId = :KeyId
What should the value of parameter :KeyId be so that WHERE clause has no
effect?
(i.e. returns all records)
Thanks
Ramtin Kazemi
|
|
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Fri Jul 09, 2004 1:09 pm Post subject: Re: WHERE clause |
|
|
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote in news:40ee7810
@newsgroups.borland.com:
| Quote: | I am using MS-SQL Server and column type is 'int' .
What should I do now?
|
See Paulo's message.
--
Iman
|
|
| Back to top |
|
 |
Tim Radford Guest
|
Posted: Fri Jul 09, 2004 1:47 pm Post subject: Re: WHERE clause |
|
|
You could try
SELECT * FROM MyTable WHERE :KeyID = -1 OR KeyId = :KeyId
Then supplying a value of -1 will return all rows
Tim
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote
| Quote: | Hi
consider following SQL command :
SELECT * FROM MyTable WHERE KeyId = :KeyId
What should the value of parameter :KeyId be so that WHERE clause has no
effect?
(i.e. returns all records)
Thanks
Ramtin Kazemi
|
|
|
| Back to top |
|
 |
Ramtin Kazemi Guest
|
Posted: Fri Jul 09, 2004 3:50 pm Post subject: Re: WHERE clause |
|
|
Hi Tim
I tried your solution but got this error :
---------------------------
Error
---------------------------
dbExpress Error: Invalid Parameter.
---------------------------
OK
---------------------------
Regards
K.Ramtin
|
|
| Back to top |
|
 |
Ramtin Kazemi Guest
|
Posted: Fri Jul 09, 2004 4:00 pm Post subject: Re: WHERE clause |
|
|
Hi Paulo
How should I set the parameter value to "isnull( :KeyID, t.KeyID)" ?
I didn't understand.
Regards
K.ramtin
|
|
| Back to top |
|
 |
Ramtin Kazemi Guest
|
Posted: Fri Jul 09, 2004 4:02 pm Post subject: Re: WHERE clause |
|
|
Hi Tim
I tried your solution but got this error :
---------------------------
Error
---------------------------
dbExpress Error: Invalid Parameter.
---------------------------
OK
---------------------------
Regards
K.Ramtin
|
|
| Back to top |
|
 |
Oscar Santiesteban Jr. Guest
|
Posted: Sun Jul 11, 2004 12:44 am Post subject: Re: WHERE clause |
|
|
What I would do is have something like this: (some code,some pseudo-code)
adoquery1.sql.clear;
adoquery1.sql.add('select * from mytable');
if keyid > 0 then // or whatever condition indicating that you want
some specific records
begin
adoquery1.sql.add('where keyid = ' + inttostr(keyid))
end;
adoquery1.open;
This assumes that KEYID is an INT like you mentioned.
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote
| Quote: | Hi
consider following SQL command :
SELECT * FROM MyTable WHERE KeyId = :KeyId
What should the value of parameter :KeyId be so that WHERE clause has no
effect?
(i.e. returns all records)
Thanks
Ramtin Kazemi
|
|
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Sun Jul 11, 2004 3:49 am Post subject: Re: WHERE clause |
|
|
"Ramtin Kazemi" <Ramtin76Hz (AT) hotmail (DOT) com> wrote in
news:40efcf0e (AT) newsgroups (DOT) borland.com:
| Quote: | How should I set the parameter value to "isnull( :KeyID, t.KeyID)" ?
I didn't understand.
|
You need to clear the KeyId parameter. ParamByName('KeyID').Clear;
Iman
|
|
| Back to top |
|
 |
Dennis Passmore Guest
|
Posted: Sun Jul 11, 2004 5:42 pm Post subject: Re: WHERE clause |
|
|
declare @fkeyid int
select @fKeyid = :Keyid
SELECT * FROM MyTable
WHERE @fKeyid is null
OR KeyId = @fKeyId
Dennis Passmore
Ultimate Software, Inc.
|
|
| Back to top |
|
 |
Ramtin Kazemi Guest
|
Posted: Mon Jul 12, 2004 6:54 pm Post subject: Re: WHERE clause |
|
|
Hi Tim !
You are right , It works
Thanks
K.Ramtin
|
|
| Back to top |
|
 |
|