Thursday, October 9, 2008

Advance search using xml (SQL Query)

SELECT vwCarReservationsforVendorCost.VendorId, vwCarReservationsforVendorCost.VendorName, SUM(isnull (vwCarReservationsforVendorCost.VendorcostinRs,0)) AS Total,Sum (isnull(tblVendorPaymentVouchers.Amount,0)) AS AmountPaid, (SUM(isnull (vwCarReservationsforVendorCost.VendorcostinRs,0))-Sum (isnull(tblVendorPaymentVouchers.Amount,0))) AS Outstanding
FROM vwCarReservationsforVendorCost
LEFT OUTER JOIN tblVendorPaymentVouchers ON
tblVendorPaymentVouchers.VendorId=vwCarReservationsforVendorCost.VendorId
WHERE (ReservedDate >= @OrderDateFrom OR @OrderDateFrom = '01/01/1900') AND
(ReservedDate<=@OrderDateTo OR @OrderDateTo='01/01/1900') AND
(vwCarReservationsforVendorCost.vendorId in (SELECT VendorId FROM OPENXML (@iDoc, '/VENDORS/VENDOR',1) WITH (VendorId INT)) OR @Vendors='')
GROUP BY vwCarReservationsforVendorCost.VendorId,vwCarReservationsforVendorCost.VendorName



//this is how you enter the parameters from front end

foreach (ListItem item in lbDeliveryService.Items)
{
if (item.Selected)
{
sbVender.AppendFormat("", item.Value.ToString());
}
}
sbVender.Append("");


DataSet ds = OBJOrder.SearchVendorDeliverCostAnalysisReports(fromDate, toDate, sbVender.ToString());

No comments: