on 2024 Jan 08 4:55 PM
Hi, I am using Crystal Reports 2016 for Sage to pull data for itemcodes which have may have one or more binlocations using the COMMAND feature. The subquery needs to pull a certain number of itemcodes. The outer query then selects additional data (represented by the ... in the query below) for those itemcodes. If each itemcode has only one binlocation, three rows of data should be output. If one or more itemcodes has more than one binlocation, a row should be output for each of the itemcode/binlocation combinations.
The query works fine if I specify an itemcode in the subquery and specify 'x.itemcode =' in the outer query.
If I run the query as shown below with 'TOP 3' in the subquery and 'x.itemcode IN' in the outer query, the query never returns, and I have to kill CR and start again.
Please advise how I can correct. Thanks!
SELECT
x.itemcode
...
FROM
ci_item x
WHERE
x.itemcode IN
(
SELECT TOP 3
a.itemcode
FROM
ci_item a
,im_itemwarehouse b
WHERE
a.itemcode = b.itemcode
and b.warehousecode = '002'
and a.udf_inventory_class = 'HDHV'
and a.lastphysicalcountdate is null
and b.quantityonhand <> 0
)
Request clarification before answering.
Hey Jamie,
I did start out using LIMIT and it wouldn't run. That's how I wound up with TOP which is happy unless it is in a subquery...
Thanks!
Lori
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The only other suggestions I can think of, if you want to pursue the Command object method, would be to:
As Dell mentioned there is a built-in Top N in Crystal which would avoid this issue.
Hi,
I think both of you are correct in that the DB we are using is balking at my wishes. We use Providex, so we don't have the Sage version with SQL. I unfortunately do not have any other means to send my query to the DB. I will try the TopN and see if I can get that to help. This may turn out to be a report that really needs a nice programming language like SAS to get the job done.
Thanks!
Lori
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok...another suggestion is to try using a LIMIT in the subquery after the ORDER BY...i.e. eliminate the TOP N part of the subquery. As Dell mentions, this could be a DB limitation. It'd be good to know what DB your Sage system is using.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe this is a limitation of how your database operates and has nothing really to do with Crystal. What type and version of database is your Sage system working on? Have you tried running your query in a tool other than Crystal that connects to your database? I don't think it will work there either.
One option that might work for you would be to use the TopN functionality that's built into Crystal.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
No other commands or tables are used. Since the subquery runs ok without the outer query, I figure I am violating a rule I don't know about regarding SQL when using COMMAND.
Thanks!
Lori
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Adding the ORDER BY to the subquery works only if I remove the outer query. ie the subquery runs fine on its own with both the ORDER BY and the TOP. Thanks for the thoughts!
Lori
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lori, does adding an ORDER BY in your TOP N subquery make a difference? And if you then run the subquery on its own does that work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.