日期:2014-05-17 浏览次数:20455 次
ALTER PROCEDURE [dbo].[SP_T_Operation_SelectAll] ( @SheetType varchar(10), @date1 varchar(25), @date2 varchar(25), @SheetOwner varchar(10), @CostCenterCode varchar(10), @ProductName nvarchar(100) ) AS BEGIN DECLARE @sql nvarchar(MAX) SET @sql =' select a.SheetID,a.OperationDate,a.SheetType, c.ProductName,b.Quantity,b.UnitPrice, d.UserName,b.CostCenterCode from T_Operation a left join T_OperationDetail b on a.SheetID=b.SheetID left join T_Product c on b.ProductID=c.ProductID left join T_User d on a. SheetOwner=d.UserID where 1=1 ' IF @SheetType IS NOT NULL AND @SheetType <>'' SET @sql=@sql+' and A.SheetType ='+@SheetType; IF @date1 IS NOT NULL AND @date1<>'' and @date2 IS NOT NULL AND @date2<>'' SET @sql=@sql+' and A.OperationDate >='+@date1+' and A.OperationDate <='+@date2; IF @SheetOwner IS NOT NULL AND @SheetOwner<>'' SET @sql=@sql+' and d.UserName LIKE(''%'+@SheetOwner+'%'')'; IF @CostCenterCode IS NOT NULL AND @CostCenterCode<>'' SET @sql=@sql+' and B.CostCenterCode LIKE(''%'+@CostCenterCode+'%'')'; IF @ProductName IS NOT NULL AND @ProductName<>'' SET @sql=@sql+' and C.ProductName LIKE(''%'+@ProductName+'%'')'; PRINT (@sql) EXEC (@sql) END
and A.OperationDate >=012/7/18 0:00:00:00 and A.OperationDate <=2012/7/18 0:00:00:00