Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

how to bind the DataSet(columns generate dynamically from SQL PROC) to Crystal Report

$
0
0

I have create a procedure to retrive the result of MonthlyTotal for each customer on a region, but the months  are generated depend on query condition. result looks like

RegionCustomerName2013-112013-122014-012014-02
MonthlyTotalReduce TotalMonthlyTotalReduce TotalMonthlyTotalReduce TotalMonthlyTotalReduce Total
JiangsuRestaurantNULLNULLNULLNULL38101161503.5
ShangHaiMarket22002.520023NULLNULLNULLNULL
ZheJiangMarket22002.520023NULLNULL122073
ZheJiangRestaurantNULLNULLNULLNULLNULLNULL15023

now I met the issue is: I want to display the results in Crystal Report, since the DataSet 'year-month' column will  be generated in Runtime depend on the user input startdate/enddate,  so I can't drag/drop the columns in Crystal Report when design.  my proc code is:

ALTER PROCEDURE [dbo].[GetMonthlyTotal]
	-- Add the parameters for the stored procedure here
 @startDate date,
 @endDate date
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	if not object_id('tempdb..#a2') is null  
	drop table #a2
	declare @s nvarchar(4000)	
	SELECT region,CustomerName,MonthlyTotal,CONVERT(char(7),recordDate,120) recordDate into #a2 FROM MonthlySaleTest where recordDate between @startDate and @endDate
	
	Select     @s=isnull(@s+',','')+quotename([recordDate]) from #a2 group by [recordDate]
	exec('select * from #a2  pivot (sum([MonthlyTotal]) for [recordDate] in('+@s+'))b order by region,CustomerName')
END


Is there a way to work around that can be display all the dataset data in crystal report wihch get from database.

 

 


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>