Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Cast in Where statement?
Fri, Sep 22 2017 2:24 AMPermanent Link

Adam H.

Hi,

I was just wondering if I'm doing something wrong, or if conditions can't include cast statements.

In my SQL I'm wanting to only select records where the weighin timestamp has the same date as the weighout timestamp:

select Cast(Weighin as Date), Cast(Weighout as Date), weighin, weighout, Weighout-WeighIn as Diff
From Tickets
where
(Cast(WeighIn as Date) <> Cast(WeighOut as Date))  /* Make sure they fall on the same day*/
order by diff desc

... which ends up giving me records with different dates.

If Cast isn't permitted in the where statement is there another approach I can use to obtain this information. (Short of using memory tables and selecting into a memory table, and then querying that - I'm trying to avoid memory tables where possible to become more EDB Port friendly).
Fri, Sep 22 2017 3:29 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


Just tried here on my old version of DBISAM and its fine. But, if you want them on the same day shouldn't the condition be

(Cast(WeighIn as Date) = Cast(WeighOut as Date))

Roy Lambert
Sun, Sep 24 2017 8:56 PMPermanent Link

Adam H.

Hi Roy,

Thanks,and yes - you're right it should be =, and not <>

The problem I seem to be getting is with a larger query. it seems to be giving me records that include dates outside of the range...

select cast('MAX_DAILY_TURNAROUND' as VARCHAR(40)) as Item, Type, max(Weighout-WeighIn) as Diff
Into Memory\X1
from Tickets
where
/*101*/ (weighin > current_date - 600)
/*1001* and (Not Archived)
and (Cast(WeighIn as Date) = Cast(WeighOut as Date))  /* Make sure they fall on the same day*/
and (WeighIn <> WeighOut) /* Exclude any where the same time exists for them both */
and (not Rejected)
group by Type
Sun, Sep 24 2017 8:58 PMPermanent Link

Adam H.

And I've just found the issue:

it's line:

/*1001* and (Not Archived)

it's missing the closing terminator, and should be:

/*1001*/ and (Not Archived).

So it's actually ignoring the condition directly below it...

I was looking at cast being the issue, but instead it's my sloppy touch-typing. Smile
Mon, Sep 25 2017 1:58 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


What you do now is go into preferences and set comments to dull yellow that you have to strain to read <vbg>

Roy Lambert
Tue, Sep 26 2017 3:08 AMPermanent Link

Adam H.

Great idea - but I don't think I have that option in XE2 - at least for TStrings, or even SQL Comments (if I 'view in editor').

It works for other comments such as

(* comments *)
// Comments, and
{ Comments}

but not for

/* Comments */
Tue, Sep 26 2017 3:38 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


>Great idea - but I don't think I have that option in XE2 - at least for TStrings, or even SQL Comments (if I 'view in editor').
>
>It works for other comments such as
>
>(* comments *)
>// Comments, and
>{ Comments}
>
>but not for
>
>/* Comments */

I was thinking EDBManager, however, great minds to the rescue - change your sql comments to /* { .... }*/

cue sound of mad cackling laughter

Roy

Wed, Sep 27 2017 7:41 PMPermanent Link

Adam H.

> I was thinking EDBManager, however, great minds to the rescue - change your sql comments to /* { .... }*/
> cue sound of mad cackling laughter

LOL - Nice one Roy, but wouldn't work if I made the same mistake...

ie

Where
(True)
/* {.......} *   and (Something else)
/* {.......} */  and (Another thing)...


... something else would be ignored because of the bad termination. But I like the way your mind thinks outside the box. Wink
Image