views:

37

answers:

3

I need to pass a list of key values to a stored procedure in SQL-Server, and that stored procedure then returns back the values needed for a Crystal Report.

Rather than sending a comma separated list and then parsing that, it was suggested that I use a Table Type. So, I've defined that table type as simply made of integers:

CREATE TYPE [dbo].[SiteIdentifiers] AS TABLE 
(
    [SiteId]     BigInt, 
    PRIMARY KEY ([SiteId])
)

However, now I need to modify my Crystal Report to take that as an input parameter. (The stored procedure starts with...

CREATE  PROCEDURE [dbo].[sp_SiteReport]
    @SiteIds    [dbo].[SiteIdentifiers] ReadOnly
AS

The Reports will mostly be called with ColdFusion or C#.net, so I don't think there will be an issue in adding IDs to the table type. But I don't know how to define that parameter in Crystal. The list of Types in the Create New Parameter wizard is rahter scant.

A: 

I don't think you're using the Parameter concept in Crystal the right way. To my knowledge, it's best used for manually entering data (and you're trying to pass a multi-dimensional array, not the best use of it). I recommend:

  1. Your first idea of feeding in the table as a comma-delimited string.
    OR
  2. Saving your procedure's output to a temporary table in the SQL-Server and importing that.
PowerUser
If the stored procedure needs parameters, won't Crystal need to specify them? That's not to say that I won't end up using a comma delimited string, but more the initial point you make about not using parameters correctly. If I'm going to use Crystal, and the stored procedures needs parameters, it seems that IS the point of the parameters.
thursdaysgeek
Ah, didn't realize that the stored proc needed parameters (even though you clearly said so). In that case, do the parameters absolutely need to be generated by Crystal? What if you run the proc first, feed it with a query that's stored on the sql-server, and then run Crystal?
PowerUser
A: 

Normally, a Crystal report that runs off a procedure is created by pointing the report at the procedure - any required parameters for the procedure are automatically generated in the report. If you have done this in the Crystal Reports designer without the report generating the table input parameter, then I don't think you can do it this way.

As another alternative to using a comma-separated list, have you considered:

  • creating a table to hold session IDs and input values,
  • populating the table just prior to running the report with a session ID and the input values required,
  • passing the session ID to the report as a parameter,
  • passing the session ID from the report to the procedure as a parameter,
  • coding the procedure to select the input values from the new table based on the session ID, and removing the entries for the session ID after running the report?
Mark Bannister
A: 

As far as I can tell, this is not possible. Crystal does not take data types that it doesn't recognize from other applications, such as SQL Server.

thursdaysgeek