The below is the stored procedure code:
CREATE PROCEDURE [ReportAllSpecified] @partnerID int,@groupID int,@destinationID int,@fromDate varchar(50),@toDate varchar(50),@reportType varchar(50),@orderByType varchar(50)
AS
If (@reportType = 'All')
Begin
Select grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName, ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName, cust.customerID
From orders ord Inner Join customerTransaction ct On ord.orderid=ct.orderid And CAST(ord.orderDate As datetime) between @fromDate And @toDate
Inner join batch bth On ct.batchid=bth.batchid Inner join groupp grp on bth.groupid=grp.groupid And grp.groupid=@groupID
inner Join location loc On bth.locationid=loc.locationid And loc.locationid=@destinationID Inner join customer cust
on ord.userid=cust.userid Inner Join partnerMaster pm On ord.partnerid=pm.partnerid And pm.partnerid=@partnerID
Group By grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
Order By
case when @orderByType = 'grp.groupID ASC' then grp.groupName end ASC,
case when @orderByType = 'grp.groupID DESC' then grp.groupName end DESC ,
case when @orderByType = 'ord.orderDate ASC' then ord.orderDate end ASC,
case when @orderByType = 'ord.orderDate DESC' then ord.orderDate end DESC,
case when @orderByType = 'pm.NimbusPartnerCode ASC' then pm.NimbusPartnerCode end ASC,
case when @orderByType = 'pm.NimbusPartnerCode DESC' then pm.NimbusPartnerCode end DESC,
case when @orderByType = 'ct.ControlID ASC' then ct.ControlID end ASC,
case when @orderByType = 'ct.ControlID DESC' then ct.ControlID end DESC,
case when @orderByType = 'ct.rechargable ASC' then ct.rechargable end ASC,
case when @orderByType = 'ct.rechargable DESC' then ct.rechargable end DESC,
case when @orderByType = 'grp.vendorID ASC' then grp.vendorID end ASC,
case when @orderByType = 'grp.vendorID DESC' then grp.vendorID end DESC,
--case when @orderByType = 'ord.OrderId ASC' then ord.OrderId end ASC ,
--case when @orderByType = 'ord.OrderId DESC' then ord.OrderId end DESC ,
case when @orderByType = 'ct.PINNo ASC' then ct.PINNo end ASC,
case when @orderByType = 'ct.PINNo DESC' then ct.PINNo end DESC,
case when @orderByType = 'cust.name ASC' then cust.name end ASC,
case when @orderByType = 'cust.name DESC' then cust.name end DESC,
case when @orderByType = 'ct.cardName ASC' then grp.groupName end ASC,
case when @orderByType = 'ct.cardName DESC' then grp.groupName end DESC,
case when @orderByType = 'cust.customerID ASC' then cust.customerID end ASC,
case when @orderByType = 'cust.customerID DESC' then cust.customerID end DESC,
case when @orderByType = 'loc.locationName ASC' then loc.locationName end ASC,
case when @orderByType = 'loc.locationName DESC' then loc.locationName end DESC,
case when @orderByType = 'ord.attendedBy ASC' then ord.attendedBy end ASC,
case when @orderByType = 'ord.attendedBy DESC' then ord.attendedBy end DESC,
case when @orderByType = 'ct.rate ASC' then ct.rate end ASC,
case when @orderByType = 'ct.rate DESC' then ct.rate end DESC
End
If (@reportType = 'Bought')
Begin
Select grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
From orders ord
Inner Join customerTransaction ct On ord.orderid=ct.orderid And (ct.cardName Not LIKE 'Recharge%' And ct.cardName Not LIKE 'Redeem%') And CAST(ord.orderDate As datetime) between @fromDate And @toDate
Inner join batch bth On ct.batchid=bth.batchid Inner join groupp grp on bth.groupid=grp.groupid And grp.groupid=@groupID
inner Join location loc On bth.locationid=loc.locationid And loc.locationid=@destinationID Inner join customer cust
on ord.userid=cust.userid Inner Join partnerMaster pm On ord.partnerid=pm.partnerid And pm.partnerid=@partnerID
Group By grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
Order By
case when @orderByType = 'grp.groupID ASC' then grp.groupName end ASC,
case when @orderByType = 'grp.groupID DESC' then grp.groupName end DESC ,
case when @orderByType = 'ord.orderDate ASC' then ord.orderDate end ASC,
case when @orderByType = 'ord.orderDate DESC' then ord.orderDate end DESC,
case when @orderByType = 'pm.NimbusPartnerCode ASC' then pm.NimbusPartnerCode end ASC,
case when @orderByType = 'pm.NimbusPartnerCode DESC' then pm.NimbusPartnerCode end DESC,
case when @orderByType = 'ct.ControlID ASC' then ct.ControlID end ASC,
case when @orderByType = 'ct.ControlID DESC' then ct.ControlID end DESC,
case when @orderByType = 'ct.rechargable ASC' then ct.rechargable end ASC,
case when @orderByType = 'ct.rechargable DESC' then ct.rechargable end DESC,
case when @orderByType = 'grp.vendorID ASC' then grp.vendorID end ASC,
case when @orderByType = 'grp.vendorID DESC' then grp.vendorID end DESC,
--case when @orderByType = 'ord.OrderId ASC' then ord.OrderId end ASC ,
--case when @orderByType = 'ord.OrderId DESC' then ord.OrderId end DESC ,
case when @orderByType = 'ct.PINNo ASC' then ct.PINNo end ASC,
case when @orderByType = 'ct.PINNo DESC' then ct.PINNo end DESC,
case when @orderByType = 'cust.name ASC' then cust.name end ASC,
case when @orderByType = 'cust.name DESC' then cust.name end DESC,
case when @orderByType = 'ct.cardName ASC' then grp.groupName end ASC,
case when @orderByType = 'ct.cardName DESC' then grp.groupName end DESC,
case when @orderByType = 'cust.customerID ASC' then cust.customerID end ASC,
case when @orderByType = 'cust.customerID DESC' then cust.customerID end DESC,
case when @orderByType = 'loc.locationName ASC' then loc.locationName end ASC,
case when @orderByType = 'loc.locationName DESC' then loc.locationName end DESC,
case when @orderByType = 'ord.attendedBy ASC' then ord.attendedBy end ASC,
case when @orderByType = 'ord.attendedBy DESC' then ord.attendedBy end DESC,
case when @orderByType = 'ct.rate ASC' then ct.rate end ASC,
case when @orderByType = 'ct.rate DESC' then ct.rate end DESC
End
If (@reportType = 'Recharges')
Begin
Select grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
From orders ord
Inner Join customerTransaction ct
On ord.orderid=ct.orderid And (ct.cardName LIKE 'Recharge%') And CAST(ord.orderDate As datetime) between @fromDate And @toDate
Inner join batch bth
On ct.batchid=bth.batchid
Inner join groupp grp
on bth.groupid=grp.groupid And grp.groupid=@groupID
inner Join location loc
On bth.locationid=loc.locationid And loc.locationid=@destinationID
Inner join customer cust
on ord.userid=cust.userid
Inner Join partnerMaster pm
On ord.partnerid=pm.partnerid And pm.partnerid=@partnerID
Group By grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
Order By
case when @orderByType = 'grp.groupID ASC' then grp.groupName end ASC,
case when @orderByType = 'grp.groupID DESC' then grp.groupName end DESC ,
case when @orderByType = 'ord.orderDate ASC' then ord.orderDate end ASC,
case when @orderByType = 'ord.orderDate DESC' then ord.orderDate end DESC,
case when @orderByType = 'pm.NimbusPartnerCode ASC' then pm.NimbusPartnerCode end ASC,
case when @orderByType = 'pm.NimbusPartnerCode DESC' then pm.NimbusPartnerCode end DESC,
case when @orderByType = 'ct.ControlID ASC' then ct.ControlID end ASC,
case when @orderByType = 'ct.ControlID DESC' then ct.ControlID end DESC,
case when @orderByType = 'ct.rechargable ASC' then ct.rechargable end ASC,
case when @orderByType = 'ct.rechargable DESC' then ct.rechargable end DESC,
case when @orderByType = 'grp.vendorID ASC' then grp.vendorID end ASC,
case when @orderByType = 'grp.vendorID DESC' then grp.vendorID end DESC,
--case when @orderByType = 'ord.OrderId ASC' then ord.OrderId end ASC ,
--case when @orderByType = 'ord.OrderId DESC' then ord.OrderId end DESC ,
case when @orderByType = 'ct.PINNo ASC' then ct.PINNo end ASC,
case when @orderByType = 'ct.PINNo DESC' then ct.PINNo end DESC,
case when @orderByType = 'cust.name ASC' then cust.name end ASC,
case when @orderByType = 'cust.name DESC' then cust.name end DESC,
case when @orderByType = 'ct.cardName ASC' then grp.groupName end ASC,
case when @orderByType = 'ct.cardName DESC' then grp.groupName end DESC,
case when @orderByType = 'cust.customerID ASC' then cust.customerID end ASC,
case when @orderByType = 'cust.customerID DESC' then cust.customerID end DESC,
case when @orderByType = 'loc.locationName ASC' then loc.locationName end ASC,
case when @orderByType = 'loc.locationName DESC' then loc.locationName end DESC,
case when @orderByType = 'ord.attendedBy ASC' then ord.attendedBy end ASC,
case when @orderByType = 'ord.attendedBy DESC' then ord.attendedBy end DESC,
case when @orderByType = 'ct.rate ASC' then ct.rate end ASC,
case when @orderByType = 'ct.rate DESC' then ct.rate end DESC
End
If (@reportType = 'LBRedeemed')
Begin
Select grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
From orders ord
Inner Join customerTransaction ct
On ord.orderid=ct.orderid And (ct.cardName LIKE 'Redeem%') And CAST(ord.orderDate As datetime) between @fromDate And @toDate
Inner join batch bth
On ct.batchid=bth.batchid
Inner join groupp grp
on bth.groupid=grp.groupid And grp.groupid=@groupID
inner Join location loc
On bth.locationid=loc.locationid And loc.locationid=@destinationID
Inner join customer cust
on ord.userid=cust.userid
Inner Join partnerMaster pm
On ord.partnerid=pm.partnerid And pm.partnerid=@partnerID
Group By grp.groupName,grp.vendorid, pm.NimbusPartnerCode, loc.locationName,
ord.orderDate,ct.rate,ord.attendedBy,ct.rechargable, ct.ControlID,
ct.orderId,ct.PINNo,cust.name,ord.userid,ct.cardName,
cust.customerID
Order By
case when @orderByType = 'grp.groupID ASC' then grp.groupName end ASC,
case when @orderByType = 'grp.groupID DESC' then grp.groupName end DESC ,
case when @orderByType = 'ord.orderDate ASC' then ord.orderDate end ASC,
case when @orderByType = 'ord.orderDate DESC' then ord.orderDate end DESC,
case when @orderByType = 'pm.NimbusPartnerCode ASC' then pm.NimbusPartnerCode end ASC,
case when @orderByType = 'pm.NimbusPartnerCode DESC' then pm.NimbusPartnerCode end DESC,
case when @orderByType = 'ct.ControlID ASC' then ct.ControlID end ASC,
case when @orderByType = 'ct.ControlID DESC' then ct.ControlID end DESC,
case when @orderByType = 'ct.rechargable ASC' then ct.rechargable end ASC,
case when @orderByType = 'ct.rechargable DESC' then ct.rechargable end DESC,
case when @orderByType = 'grp.vendorID ASC' then grp.vendorID end ASC,
case when @orderByType = 'grp.vendorID DESC' then grp.vendorID end DESC,
--case when @orderByType = 'ord.OrderId ASC' then ord.OrderId end ASC ,
--case when @orderByType = 'ord.OrderId DESC' then ord.OrderId end DESC ,
case when @orderByType = 'ct.PINNo ASC' then ct.PINNo end ASC,
case when @orderByType = 'ct.PINNo DESC' then ct.PINNo end DESC,
case when @orderByType = 'cust.name ASC' then cust.name end ASC,
case when @orderByType = 'cust.name DESC' then cust.name end DESC,
case when @orderByType = 'ct.cardName ASC' then grp.groupName end ASC,
case when @orderByType = 'ct.cardName DESC' then grp.groupName end DESC,
case when @orderByType = 'cust.customerID ASC' then cust.customerID end ASC,
case when @orderByType = 'cust.customerID DESC' then cust.customerID end DESC,
case when @orderByType = 'loc.locationName ASC' then loc.locationName end ASC,
case when @orderByType = 'loc.locationName DESC' then loc.locationName end DESC,
case when @orderByType = 'ord.attendedBy ASC' then ord.attendedBy end ASC,
case when @orderByType = 'ord.attendedBy DESC' then ord.attendedBy end DESC,
case when @orderByType = 'ct.rate ASC' then ct.rate end ASC,
case when @orderByType = 'ct.rate DESC' then ct.rate end DESC
End
GO
Is it correct to write such a long SP?Moreover when I pass the para to the SP from my asp page it gives the foll error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function ReportAllSpecified has too many arguments specified.
/controlpannel/generateReport.asp, line 240
Which was not there until I added one more para ie.@orderByType To my SP for the value for order by clause.
Please help me as where iam lacking.
Thankz.