Solved

Recursive Query in Crystal Reports on SQL Server

Posted on 2013-06-12
4
1,394 Views
Last Modified: 2013-06-12
Good morning -
I have a recursive query on two tables:
ADUsers and Groups with about 24,000 records
Groups with about 120,000 records  (With selection criteria - this is whittled down to 4600)

Here's the query:
WITH EmployeeList AS
(SELECT      A.DistinguishedName,
                      A.AccountName,
                      A.DisplayName,
                      A.Type,
                      B.MEMBEROF,
                      B.USERNAME
FROM         ADUsersAndGroups A,
                    GROUPS B
WHERE     A.type = 'User'
AND           B.MEMBEROF LIKE '%HEALTH_%'
                 
UNION ALL

SELECT      A.DistinguishedName,
                      A.AccountName,
                      A.DisplayName,
                      A.Type,
                      B.MEMBEROF,
                     B.USERNAME
FROM         ADUsersAndGroups A,
                    GROUPS B
WHERE     A.type = 'Group'
AND           B.MEMBEROF LIKE '%HEALTH_%')
SELECT * FROM EmployeeList  

Problem:  When I attempt to run this in Crystal Reports I'm put in an infinite loop... with last record count at about 32M records before my system ran out of memory.    When I change the syntax to just UNION or limit the record count, Crystal Reports locks up after 5-10 mins when I try to save the command window.

Is there a more efficient or better way to handle this?   I tried using the sub report approach but have issues with the output and subreports using CSV formatting.

Any help would be appreciated.    Thanks, Mojeaux
0
Comment
Question by:mojeaux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Accepted Solution

by:
vasto earned 167 total points
ID: 39241497
You need ; at the end of
SELECT * FROM EmployeeList  


SELECT * FROM EmployeeList  ;
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 167 total points
ID: 39241671
You need to join the tables.   What you have now is a cross join between ADUsersandGroups and GROUPS.

Every user record in ADUsersandGroups is selected then joined to every record in B where Memberof has Health in the name.  Similarly for the second query.

mlmcc
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 166 total points
ID: 39241886
In addition, for recursion you should have EmployeeList as a JOIN to the second query as well as a filter condition that stops recursion at some point.
0
 

Author Closing Comment

by:mojeaux
ID: 39242293
Thank you for catching the syntax and the additional information regarding the second query.   I will give these a try.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question