Solved

Recursive Query in Crystal Reports on SQL Server

Posted on 2013-06-12
4
1,376 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
I recently went through setting up a JasperReports Server using the AWS EC2 instance, and this article will cover some basic administration tasks I had to perform.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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