0

I currently have a Database Command object in my Crystal Report that looks something like

SELECT *
    FROM table
    WHERE field = {?EndDate}

I want to change it so it looks more like

IF {?EndDate} = DATE '1900-01-01' 
    MyVariable = ADD_MONTHS(LAST_DAY(SYSDATE), -1)
ELSE
    MyVariable = {?EndDate}

SELECT * 
    FROM table
    WHERE field = MyVariable

I kind of get the idea of how to build a dynamic query to do this, but I don't know if that's really what I want to do. Could someone point me in the right direction, please? Thanks.

1 Answer 1

1
Select * 
from table
where field = decode
         (myvariable,'1900-01-01',ADD_MONTHS(LAST_DAY(SYSDATE), -1)
                    ,myvariable)

[Reads: select * from my table where field is equal to.. Decode myvariable; if it's 1-1-1900, then get a month before the current sysdate, otherwise, use the variable]

Something like that.

Sign up to request clarification or add additional context in comments.

3 Comments

Ah, that makes it a bit easier. Wordy, since I use it about 5 times, but doable. Thanks!
This way you don't need to worry about variable declarations, so it might be a tad easier for you. The duplication isn't as bad as it seems, but it's duplication none the less.
Well, I don't mind worrying about variable declarations, if it'll make the code any more efficient...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.