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
Solved

Recursive Query in Crystal Reports on SQL Server

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error Creating Foreign Keys in SQL Database 7 45
SSRS - Image from DB has ugly blue border !? 8 40
TSQL recursive CTE challenge... 8 29
query optimization 6 14
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

856 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