set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[STPListGoodReport2] @__GoodCode int =0 , @__PersonCode int=0, @FormCaption nvarchar(1000) output AS set @FormCaption='' if @__PersonCode>0 SELECT @FormCaption=Title + '- ' + CAST(AccountSysCode AS nvarchar(1000)) FROM CodeMNGDWNTbl WHERE (AccountSysCode = @__PersonCode) if @__GoodCode>0 SELECT @FormCaption = @FormCaption + ' ** ' + Title + '- ' + CAST(GoodSyscode AS nvarchar(1000)) FROM StockTbl if (@__PersonCode>0 and @__GoodCode>0) begin SELECT Quantity, Fee, UnitRate, SerialNo, InvoiceDate, InvoiceSerialNo, Size, WareHouse, Color, CustomerName, InvoiceType, AccountTitle, NetQuantity, GoodTitle, RecivedDate, Term, Comment, Unit, FK_DocsysCode, GoodSysCode, FK_AccountSysCode, Amani, Fee * NetQuantity AS Amount FROM VWGoodReport WHERE (NOT (FK_DocsysCode IS NULL)) AND (GoodSysCode = @__GoodCode) AND (FK_AccountSysCode = @__PersonCode) OR (GoodSysCode = @__GoodCode) AND (FK_AccountSysCode = @__PersonCode) AND (Amani = 1)return end if (@__GoodCode>0) begin SELECT Quantity, Fee, UnitRate, SerialNo, InvoiceDate, InvoiceSerialNo, Size, WareHouse, Color, CustomerName, InvoiceType, AccountTitle, NetQuantity, GoodTitle, RecivedDate, Term, Comment, Unit, FK_DocsysCode, GoodSysCode, FK_AccountSysCode, Amani, Fee * NetQuantity AS Amount FROM VWGoodReport WHERE (NOT (FK_DocsysCode IS NULL)) AND (GoodSysCode = @__GoodCode) OR (GoodSysCode = @__GoodCode) AND (Amani = 1) return end if (@__PersonCode>0 ) begin SELECT Quantity, Fee, UnitRate, SerialNo, InvoiceDate, InvoiceSerialNo, Size, WareHouse, Color, CustomerName, InvoiceType, AccountTitle, NetQuantity, GoodTitle, RecivedDate, Term, Comment, Unit, FK_DocsysCode, GoodSysCode, FK_AccountSysCode, Amani, Fee * NetQuantity AS Amount FROM VWGoodReport WHERE (NOT (FK_DocsysCode IS NULL)) AND (FK_AccountSysCode = @__PersonCode) OR (FK_AccountSysCode = @__PersonCode) AND (Amani = 1) return end SELECT Quantity, Fee, UnitRate, SerialNo, InvoiceDate, InvoiceSerialNo, Size, WareHouse, Color, CustomerName, InvoiceType, AccountTitle, NetQuantity, GoodTitle, RecivedDate, Term, Comment, Unit, FK_DocsysCode, GoodSysCode, FK_AccountSysCode, Amani, Fee * NetQuantity AS Amount FROM VWGoodReport WHERE (NOT (FK_DocsysCode IS NULL)) OR (Amani = 1)