Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: A working query in Toad returns empty in Crystal Post Reply Post New Topic
Page  of 2 Next >>
Author Message
lukavog
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: Slovenia
Online Status: Offline
Posts: 13
Quote lukavog Replybullet Topic: A working query in Toad returns empty in Crystal
    Posted: 01 Aug 2013 at 1:22am
Hi!
I have this query (look down). I don't know why this query is working perfect in Toad/SQL Management and resulting problems in Crystal. Does Crystal have some limitations, I use a Windowed function and some set operations.

It is a quite interesting query and it should work under Crystal, I don't get it why I get an empty result.

Can someone please help me, otherwise I will get stessed out!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 02 Aug 2013 at 5:14am
Not sure what Toad is, nor a windowed function, but that doesn't sound like something that CR can use. CR uses pretty much plain vanilla SQL. If you want to do something special on the server for the data, I would use a stored proc that has a better chance of being understood by the server, and just return the dataset to CR.

HTH
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 02 Aug 2013 at 5:20am
Toad is a multi-platform database query tool built for anyone who needs to access data, understand data relationships, and quickly produce reports.

That being said, I normally can take any Toad query and use it in CR.  But then again lukavog appears to doing some advanced querying.

lukavog are you using the same connection in Toad as you are using in CR?
IP IP Logged
lukavog
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: Slovenia
Online Status: Offline
Posts: 13
Quote lukavog Replybullet Posted: 04 Aug 2013 at 9:59pm
"CR uses pretty much plain vanilla SQL" thi means complex queries I'm using will never work?!

"I would use a stored proc that has a better chance of being understood by the server, and just return the dataset to CR"

Totally agree whith this, I'll consider your reply and present the situation to my leaders!

Thanks a lot HTH!
-- Luka
IP IP Logged
lukavog
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: Slovenia
Online Status: Offline
Posts: 13
Quote lukavog Replybullet Posted: 04 Aug 2013 at 10:02pm
Yes Toad is just an regular DB explorer!

Yes tevray I use the same connection I think... I mean if I do a simple SELECT * from any table it work's great...

I'll post my query just for investigations purples later on!
-- Luka
IP IP Logged
lukavog
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: Slovenia
Online Status: Offline
Posts: 13
Quote lukavog Replybullet Posted: 04 Aug 2013 at 10:04pm
Here we go:

SELECT * FROM (
select
ROW_NUMBER() OVER (ORDER BY thedate ASC) AS rownumber,
sum(delay) as delay, label, thedate as start_date, DATEADD(hour, {?StepPara},thedate) AS stop_date from (

SELECT (

SELECT DiffDateA + DiffDateB + DiffDateC + DiffDateD
FROM

(
-- A case
select
case
(
select COUNT(*)
from dly_delay
--FORMAT (GETDATE (), 'yyyy/M/dd HH:00:00', 'en-US')
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
)
when 0 then 0
else
(
select DATEDIFF(MI,FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') ,end_delay) AS DiffDateA --start date
from dly_delay
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
)
end AS DiffDateA
) A

,

(
-- B case
select
case
(
select COUNT(*)
from dly_delay
where start_delay > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
when 0 then 0
else
(
select SUM(DATEDIFF(MI,start_delay, end_delay)) AS DiffDateB
from dly_delay
where start_delay > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
end AS DiffDateB
) B

,

(
-- C case
select
case
(
select COUNT(*)
from dly_delay
where start_delay < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
when 0 then 0
else
(
select DATEDIFF(MI,start_delay, FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US')) AS DiffDateC --end date
from dly_delay
where start_delay < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
end AS DiffDateC


) C

,

(
-- D case
select
case
(
select COUNT(*)
from dly_delay
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
when 0 then 0
else
(
select DATEDIFF(MI,FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') , FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US')) AS DiffDateD
from dly_delay
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
end AS DiffDateD
) D



) AS delay
     , (DATEPART(HOUR, START_DELAY)) AS label
     , START_DELAY AS thedate
     FROM (

SELECT thedate AS start_delay
      , DATEADD(hour, {?StepPara}, thedate) AS end_delay
FROM dbo.ExplodeDates2({?StopPara},DATEADD(hour, -{?StepPara}, {?StartPara}))

) mainDelay
     WHERE START_DELAY>={?StopPara} AND END_DELAY<={?StartPara}
     GROUP BY DATEPART(MONTH, START_DELAY)
               , DATEPART(DAY, START_DELAY)
               , (DATEPART(HOUR, START_DELAY) / {?StepPara})
               , START_DELAY
      , END_DELAY



UNION

-- add the gaps


(
SELECT 0 AS delay
     , (DATEPART(HOUR, thedate)) AS label
     , thedate AS thedate
FROM dbo.ExplodeDates2({?StopPara},{?StartPara})

EXCEPT

SELECT (

SELECT DiffDateA + DiffDateB + DiffDateC + DiffDateD
FROM

(
-- A case
select
case
(
select COUNT(*)
from dly_delay
--FORMAT (GETDATE (), 'yyyy/M/dd HH:00:00', 'en-US')
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
)
when 0 then 0
else
(
select DATEDIFF(MI,FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') ,end_delay) AS DiffDateA --start date
from dly_delay
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
)
end AS DiffDateA
) A

,

(
-- B case
select
case
(
select COUNT(*)
from dly_delay
where start_delay > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
when 0 then 0
else
(
select SUM(DATEDIFF(MI,start_delay, end_delay)) AS DiffDateB
from dly_delay
where start_delay > FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
end AS DiffDateB
) B

,

(
-- C case
select
case
(
select COUNT(*)
from dly_delay
where start_delay < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
when 0 then 0
else
(
select DATEDIFF(MI,start_delay, FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US')) AS DiffDateC --end date
from dly_delay
where start_delay < FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
end AS DiffDateC


) C

,

(
-- D case
select
case
(
select COUNT(*)
from dly_delay
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
when 0 then 0
else
(
select DATEDIFF(MI,FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') , FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US')) AS DiffDateD
from dly_delay
where start_delay < FORMAT(mainDelay.START_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --start date
    and end_delay   > FORMAT(mainDelay.END_DELAY, 'yyyy/M/dd HH:00:00', 'en-US') --end date
)
end AS DiffDateD
) D




) AS delay
     , (DATEPART(HOUR, START_DELAY)) AS label
     , START_DELAY AS thedate
     FROM (
SELECT thedate AS start_delay
      , DATEADD(hour, {?StepPara}, thedate) AS end_delay
FROM dbo.ExplodeDates2({?StopPara},DATEADD(hour, -{?StepPara}, {?StartPara}))
) mainDelay
     WHERE START_DELAY>={?StopPara} AND END_DELAY<={?StartPara}
     GROUP BY DATEPART(MONTH, START_DELAY)
               , DATEPART(DAY, START_DELAY)
               , (DATEPART(HOUR, START_DELAY) / {?StepPara})
               , START_DELAY
      , END_DELAY
               )
) a
GROUP BY label, thedate
) AS foo
WHERE rownumber % {?StepPara} = 0

-- Luka
IP IP Logged
lukavog
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: Slovenia
Online Status: Offline
Posts: 13
Quote lukavog Replybullet Posted: 04 Aug 2013 at 10:06pm
Woow cool this forum editor, the query is even easier to read than in Toad :)

-- Luka
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 05 Aug 2013 at 5:12am
ok, that doesn't seem too bad, though it is long...
I don't know if CR understands Row_number function, and I don't know if there is a limit to how long the select can be (again, I basically only use stored procs to drive reports) but either of those issues could be causing the issue that you are seeing (ie, nothing selected in the report)

HTH
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 05 Aug 2013 at 5:22am
I have seen far larger SQL's in crystal and it seems okay. When you write a command, crystal seems to use whatever rules the connector provides.  Without breaking the SQL down to smaller pieces and testing each one, it would be hard to figure out what it does not like.  A SP probably would be faster anyhow.

I hope this helps.
IP IP Logged
lukavog
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: Slovenia
Online Status: Offline
Posts: 13
Quote lukavog Replybullet Posted: 05 Aug 2013 at 8:16pm
When mentioning SP - "stored procedures" you mean to add a SP in the SQL engine?!
So a query in Crystal will be shorter. Also a view could solve my issue I guess, but as I am not the DB administrator things get wrong. But anyway guys thanks for replies, I'll suggest the solution to our DB administrator.
-- Luka
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.