Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Help Required in SQL expression Post Reply Post New Topic
Author Message
vipulbhatia29
Newbie
Newbie


Joined: 08 May 2009
Location: India
Online Status: Offline
Posts: 10
Quote vipulbhatia29 Replybullet Topic: Help Required in SQL expression
     Posted: 08 May 2009 at 1:51am
Hi The expression posted below is the actual SQL Expression which is required in my report:
 
((select name from (
select loc_id,name,row_number()over(  order by r)  rn from (
SELECT 0, loc_id, Misc1_txt  NAME,'A' STATUS ,rownum r
                    FROM dvxloc
                   WHERE loc_id = "XXXLOC"."LOC_ID"
                   union
SELECT     parent_loc_id, loc_id, (SELECT a.Misc1_txt
                                                     FROM dvxloc a
                                                    WHERE a.loc_id =b.loc_id) NAME,'B' ,ROWNUM
                        FROM dvxlocpath b
                  START WITH b.loc_id = "XXXLOC"."LOC_ID"
                  CONNECT BY PRIOR  parent_loc_id=loc_id
)                where name is NOT NULL        order by STATUS, R
) where rn = 1))
 
It gives an error while parsing: "XXXLOC"."LOC_ID" invalid identifier
 
LOC_ID is of numeric data type in the database. and when I run thi query in SQL editor after replacing "XXXLOC"."LOC_ID" with a numeric value say 456 . The query can be put as
((select name from (
select loc_id,name,row_number()over(  order by r)  rn from (
SELECT 0, loc_id, Misc1_txt  NAME,'A' STATUS ,rownum r
                    FROM dvxloc
                   WHERE loc_id = 456                   union
SELECT     parent_loc_id, loc_id, (SELECT a.Misc1_txt
                                                     FROM dvxloc a
                                                    WHERE a.loc_id =b.loc_id) NAME,'B' ,ROWNUM
                        FROM dvxlocpath b
                  START WITH b.loc_id = 456                  CONNECT BY PRIOR  parent_loc_id=loc_id
)                where name is NOT NULL        order by STATUS, R
) where rn = 1))
 
The above query runs flawlessly in a SQL editor and also it is parsed in Crystal SQL Expression editor without any errors.
 
I'm totally messed up of looking for altenatives. I have to deliver a report to the client and stuck on this part only.
 
The below query parses perfectly in crystal:
(select locname
from dvxloc where loc_id in(select loc3 from dvxlocpath
where loc_id = "XXXLOC"."LOC_ID"))


Edited by vipulbhatia29 - 08 May 2009 at 2:17am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 08 May 2009 at 6:30am
So can you create a stored proc to drive your report instead?  If it runs correctly in SQL, it will probably save you hours of headache in trying to figure this out.
 
While there are several commands that I have never used, the fact that it runs when table.column are replaced with a value is a stumper.  Just for fun, have you tried replacing the ""s with []s?  I have no idea if it would work, but if I was writing SQL, I would use the [] for the identifiers.
 
IP IP Logged
vipulbhatia29
Newbie
Newbie


Joined: 08 May 2009
Location: India
Online Status: Offline
Posts: 10
Quote vipulbhatia29 Replybullet Posted: 08 May 2009 at 10:28am
Originally posted by lockwelle

So can you create a stored proc to drive your report instead?  If it runs correctly in SQL, it will probably save you hours of headache in trying to figure this out.
 
While there are several commands that I have never used, the fact that it runs when table.column are replaced with a value is a stumper.  Just for fun, have you tried replacing the ""s with []s?  I have no idea if it would work, but if I was writing SQL, I would use the [] for the identifiers.
 
 
hi I have only 2 months of experience on crystal.............I know stored procedures would have beenmuch easier on this sort of code but please clarify whether stored procedures would work in the sql expression....?
 
Thanks in advance
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 May 2009 at 6:18am
Since a stored proc is nothing but a sql expression, of course it will.
 
Take your sql expression and make it a stored proc.  If you will always want only 1 value, set a parameter to the stored proc and replace "XXXLOC"."LOC_ID" with the parameter.  If you would rather that Crystal filter the records (why, SQL is designed for this, and the fewer records Crystal deals with, the faster it will run), just filter as you would if you joined directly to the tables.
IP IP Logged
vipulbhatia29
Newbie
Newbie


Joined: 08 May 2009
Location: India
Online Status: Offline
Posts: 10
Quote vipulbhatia29 Replybullet Posted: 12 May 2009 at 1:29am
I'll try this thing out today and let u know if it worked.
Thanks a lot
IP IP Logged
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