Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Select from Database using SQL Query Post Reply Post New Topic
Page  of 2 Next >>
Author Message
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Topic: Select from Database using SQL Query
     Posted: 05 Feb 2010 at 12:36pm
I'm trying to create a dynamic, cascading parameter that selects a Group Name from the database then allows me to choose the the Resource(s) from the Group(s) selected.
 
My problem is that I have multiple Groups being passed from the database and I only want to give the user the option of choosing from a few of them.
 
Example:
 
Available Groups from database:
 
10
11
Governmental
Group A
Group B
Reception
 
I only want them to be able to choose from Governmental, Group A and B and Reception.
 
When creating the cascading parameter, it pulls every group into the Available Options box.
 
I believe my fix is to create a SQL query that only selects those groups, but I have no experience with SQL whatsoever.
 
Can anyone out there help me? I would appreciate it greatly.
 
TIA
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Feb 2010 at 1:05pm
YOu can use a SQL view to do this also.
You will need access to the DB and creating a view.
What version of SQL are you using?
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 05 Feb 2010 at 1:43pm
I actually think I figured it out. I was connecting to the individual tables and then trying to create a SQL command on top of it. Wasn't working too well because it was getting quiried twice. I created a command that looks like this:
 
SELECT "Resource"."resourceName","Team"."teamName"
FROM"PhoneSystemData"."dbo"."AgentStateDetail" "AgentStateDetail" INNER JOIN "PhoneSystemData"."dbo"."Resource" "Resource" ON "AgentStateDetail"."agentID"="Resource"."resourceID" INNER JOIN "PhoneSystemData"."dbo"."Team" "Team" ON "Resource"."assignedTeamID"="Team"."teamID"
WHERE "Team"."teamName"=N'Group A' OR "Team"."teamName"=N'Group B' OR "Team"."teamName"=N'Group C' OR "Team"."teamName"=N'Group D' OR "Team"."teamName"=N'Group E' OR "Team"."teamName"=N'Group F' OR "Team"."teamName"=N'Group G' OR
"Team"."teamName"=N'Governmental' OR
"Team"."teamName"=N'Reception'

 

Items are coming through correctly. I just have to go through and add more fields to gather so I can include them in the report. Your comment did spark some ideas in me though, so thank you for that.


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Feb 2010 at 2:24pm

No prob. A view or stored proc is basically the same thing as a crystal command. If you can do commands you can do the others.

If you want you can clean up the WHERE part by using an IN statment instead of all the ORs
 
e.g.
IN ('Group A', 'Group B', 'Group C', 'Group D', ...)
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 08 Feb 2010 at 7:30am
I will look into that. Thanks.
 
I am actually now having another problem with this. I wanted to pull only those groups so that they could be seen in the Parameters view and so I could create a Cascading Parameter.
 
I also need to be able to implement the Crystal Parameters as well. For example: There is a date range for which they can choose the information. Also, they can narrow the info down by selecting one Agent to include on the report. With the current Command, it is not accepting these crystal parameters. Just wondering what I need to do to implement them into the Command.
 
Any help would be greatly appreciated.
 
Thanks.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Feb 2010 at 7:39am
I do not believe you can write parameters into a Command (as you can with a stored procedure).
You just create parameters in Crystal and use them in your crystal select statement. I would not use the date params as cascading.
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 08 Feb 2010 at 7:46am
No, I'm not using the date parameters as cascading. What I'm doing is giving them the option to choose the group for which to run the report (Group A, Group B, Group C etc..). Then when they choose the group. I want them to be able to choose the Agent(s) from the chosen group for which to run the report.
 
So the cascading parameter is the Group then Agent.
 
I tried creating a view but it said I didn't have access rights.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Feb 2010 at 7:58am
You can use the COmmand Data for that but you do not actually write it in the command. IN order fot the cascading element to work your COmmand has to retrieve all the values to persent as parameter options then in the crystal select statement you filter teh data.
Not including data params go into your report (assuming your Cmmand returns all values you want to start with).
Create a New Param (likels as a string)
make it DYNAMIC
In the Value option select the Group field from the command and click in the right column Parameters to make a parameter out of it.
Click in Row 2 of the Value column and select the Agent field from the Command and then click to create a param in that row.
Save this
Now in your crystal select statement use these 2 params you just created...something like this:
command.group=?Group and command.agent=?agent.
 
Now you can add the date range as a seperate param as either one date with a range or a begin and end date param
 
Note from a performance standpoint I prefer Views (or stored procs) to commands becuase COmamnds tend to bog my set up down considerably.


Edited by DBlank - 08 Feb 2010 at 8:01am
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 08 Feb 2010 at 8:07am
Yeah, I already have all that in place. I guess I just didn't realize that the Command was going to gather ALL the information. It definitely makes a performance difference, because If I only want to run it for one Agent, it gathers all the information for ALL agents and then limits it by the parameter. Not what I'm wanting.
 
Guess I'll be looking into Stored Procedures and Views.
 
Thanks.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Feb 2010 at 8:12am

You are in a bind there. The only way I know to limit the data retrieved via a runtime parameter is via a stored procedure. But you want a cascading parameter at runtime to assit in record selection process. In order to populate the cascading param you have to retrieve all possible records and then filter after the fact.

I know lockwelle uses SPs all the time so maybe he will chime in if I missed something or gave you bad info.
IP IP Logged
Page  of 2 Next >>
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum