queenielow
Posts: 11
|
| Posted: 07/23/2009, 11:02 PM |
|
Hi,
I had created a report using the Toolbox and my SQL query for the report is :-
select * from table where name='Queenie';
I wanted to add in another where clause based on a criteria using like this:-
if ($user_age !=''){
where name='Queenie' and user_age=$user_age;
}
How can i do that?
I've tried using $component->ds->where but it's not working at all. It seems that it omitted the new clause that i want to add in.
Thanks
|
 |
 |
DonP
|
| Posted: 07/23/2009, 11:30 PM |
|
Presuming that there has been a variable established called $user_age,
and it sometimes has a value and presuming the SQL builder is already
specifying the WHERE for name='Queenie', try something like this in a
Before Select event:
if ($user_age != '') {
$component->ds->Where = ." AND user_age = ". $user_age;
}
If $user_age is actually a field in the database, then something like
this should do it:
if ($component->ds->f(user_age) != '') {
$component->ds->Where = ." AND user_age=". $component->ds->f(user_age);
}
Either way, since you already have a WHERE clause, you need to
concatenate the secondary one to it and use the AND to tie them together.
Please note, I no longer use CCS and I'm going from memory so you'll
need to check for proper syntax but the Help files explain it all quite
well and give good examples.
Don (DonP)
queenielow wrote:
> Hi,
>
> I had created a report using the Toolbox and my SQL query for the report is :-
>
> select * from table where name='Queenie';
>
> I wanted to add in another where clause based on a criteria using like this:-
> if ($user_age !=''){
> where name='Queenie' and user_age=$user_age;
> }
>
> How can i do that?
> I've tried using $component->ds->where but it's not working at all. It seems
> that it omitted the new clause that i want to add in.
>
> Thanks
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
queenielow
Posts: 11
|
| Posted: 07/24/2009, 1:27 AM |
|
Hi DonP,
Thanks. I tried that already.
Anyway i just found out why it's not working, because i didnt use the toolbox to built the query but i just use SQL query..
Anyway thanks alot, i've figure out another way of doing it.
Cheers
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/26/2009, 2:56 PM |
|
I think Donp's solution would work if the custom code was in the beforeBuildSelect event not build select.
I think the reason is that by the time you are in build select the SQL statement has already been created from the object
In the before build select event the object still can have it's methods changed before the select statement is built.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
DonP
|
| Posted: 07/28/2009, 12:04 AM |
|
Yes, Before Build Select. As stated, I no longer use CCS so I was going
from memory. Sorry for the confusion.
Don (DonP)
queenielow wrote:
> Hi,
>
> I had created a report using the Toolbox and my SQL query for the report is :-
>
> select * from table where name='Queenie';
>
> I wanted to add in another where clause based on a criteria using like this:-
> if ($user_age !=''){
> where name='Queenie' and user_age=$user_age;
> }
>
> How can i do that?
> I've tried using $component->ds->where but it's not working at all. It seems
> that it omitted the new clause that i want to add in.
>
> Thanks
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
|