?
Solved

Recursive Query in Crystal Reports on SQL Server

Posted on 2013-06-12
4
Medium Priority
?
1,420 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 668 total points
ID: 39241497
You need ; at the end of
SELECT * FROM EmployeeList  


SELECT * FROM EmployeeList  ;
0
 
LVL 101

Assisted Solution

by:mlmcc
mlmcc earned 668 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 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 664 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Hi, In my previous Article  (http://www.experts-exchange.com/Database/Reporting/A_15199-Introduction-to-Microstrategy.html)I discussed some basic understanding of Microstrategy that how we can get in Intro of Microstrategy (MSTR). Now it's tim…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

764 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