Click here to Skip to main content
15,896,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
USE [audioitems-test]
GO
/****** Object:  StoredProcedure [dbo].[usp_Orders_GetRecordsByOrderStatus_NewSystem]    Script Date: 02/24/2014 16:55:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[usp_Orders_GetRecordsByOrderStatus_NewSystem]  
(  
 @status varchar(2),  
 @invoice varchar(20),
 @top varchar(20) 
)  
as  
begin  
declare @qry as varchar(8000);  
declare @pre as varchar(10);  
set @pre=(select [dbo].[fun_GetOrderPrefix]())  
--print @pre  
set @qry='SELECT '+@top+'orders.shipmentDetails,case orders.Printed when ''y'' then ''Yes'' else ''No'' end as PrintStatus,PrintedDate,'''+@pre+'''+CONVERT(varchar(10),orders.idorder) as idorder,orderstatus as odstatus, orders.invoiceNo, customers.idcustomer, 
orders.ShippingName+'''+' '+'''+orders.ShippingLastName+'',''+orders.shippingStateCode as shipto,orders.shippingStateCode, name+'''+' '+'''+lastName as Name, account, customerCompany,phone, email, orderDate, isnull(total,0) as total, case when orderstatus=1 
then ''Pending''  
 when orderstatus=2 then ''Delivered''  
 when orderstatus=3 then ''Cancelled''  
 when orderstatus=4 then ''Paid''  
 when orderstatus=5 then ''Chargeback''  
 when orderstatus=6 then ''Refunded''  
 when orderstatus=7 then ''Payment pending''  
 end as Status, shipmentTracking,case when CHARINDEX(''-'', transactionResults)<>0 and CHARINDEX(''-'', transactionResults) is not null then   
 substring(transactionResults,CHARINDEX(''-'', transactionResults)+1,len(transactionResults)-CHARINDEX(''-'', transactionResults)+1) else '''' end as pdate  ,  
   
 isnull( ( select top 1   Isnull(s.supplierName ,wh.wname) as name from OrderDetail od, Suppliers s ,warehouse wh,vendorOrderDetail vod  
  where   od.idvendoralloc *= s.idSupplier  
 and od.idWarehouseAlloc *= wh.idWarehouse and od.idorder = orders.idOrder and   orders.idorder *= vod.idorder and od.idproduct = vod.idproduct),  
  
  
 ( select top 1   Isnull(s.supplierName ,wh.wname) as name from OrderDetail od, Suppliers s ,warehouse wh  
  where   od.idvendoralloc *= s.idSupplier  
 and od.idWarehouseAlloc *= wh.idWarehouse and od.idorder = orders.idOrder)  
   
 )  
   
   as ShippedBy  
 FROM orders, customers where orders.idCustomer=customers.idCustomer';   
 if @status!=0  
 begin  
  if @status=8  
  begin  
   set @qry=@qry+' and (orders.viewed is null or orders.viewed=0)'  
  end  
  else  
  begin  
   set @qry=@qry+' and orderstatus='+@status  
  end  
 end  
 if @invoice!=''  
 begin  
  set @qry=@qry+' and invoiceNo='+@invoice  
 end  
set @qry=@qry+' order by orderdate desc';  
 print @qry  
execute (@qry)  
end
Posted
Updated 24-Feb-14 1:33am
v2
Comments
Gopi Kishan Mariyala 24-Feb-14 7:37am    
Do you have any linqtosql files (ex. dbml files). You can drag and drop into that files. When you are saying you want to map to which object you would like to map. Is it an entity or do you want to use this in list page kind of thing(as i see there are filters on invoice, customer)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900