Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Newbie - How to write and pass a stored proc

Author  Topic 

sgandhi
Posting Yak Master

115 Posts

Posted - 2009-04-03 : 10:07:50
Hi, i want to write a stored procedure in SQL which has multiple select statements in it and pass each of those select statements to SSRS and create different reports.

When i write the select statements SSRS only picks up on the columns from the first select (Here is an extract of my select statemnets in my stored proc

select 'Summary of Total Tax/Total Sales for Date : ' + convert(varchar,getdate()-14,106 ) as Title, sum(est_tax_price)/sum(est_item_price) as Estimated_Tax_Sales, sum(act_tax_price)/sum(act_item_price) as Actual_Tax_Sales,(sum(act_tax_price)/sum(act_item_price))-( sum(est_tax_price)/sum(est_item_price) ) as Difference,
cast((sum(act_tax_price)/sum(act_item_price))-( sum(est_tax_price)/sum(est_item_price) ) /sum(act_tax_price)/sum(act_item_price) *100 as decimal(8,2)) as Pct_tax_difference
FROM amazon_orders_difference_report
where cast("create_date" as datetime ) between getdate()-14 and getdate()



SELECT order_id, supplier_order_id, category, create_date,
est_ship_price, act_ship_total, diff_ship_price, Pct_ship_difference as Pct_ship_difference
FROM amazon_orders_difference_report
where cast("create_date" as datetime ) between getdate()-14 and getdate()
and Pct_ship_difference != 0
union
SELECT null,'SHIP_TOTALS'as Total,null,null,
sum(est_ship_price) as est_ship_price,
sum(act_ship_total) as act_ship_total,
sum(diff_ship_price) as diff_ship_price,
cast(sum(diff_ship_price)/sum(act_ship_total) *100 as decimal(8,2)) as Pct_ship_difference
FROM amazon_orders_difference_report
where cast("create_date" as datetime ) between getdate()-14 and getdate()
and Pct_ship_difference != 0
order by 2 desc

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-12 : 14:04:30
ssrs can only take metadata info from single resultset. so either you've to use two datasets one with each query or link both selects using union operator after making number of columns and column types same.
Go to Top of Page
   

- Advertisement -