الاخوة الكرام ، واخص منهم الاخ مدني المحترم ،
هذا كود استعلام في sql 2000 ، استغنيت عنه لانني لم اتمكن من الحصول على كل من output paras:
TotalRemainingAmount
CountRec
الا اذا كتبتها في جدول insert into ، يرجى مراجعة الكود واعطاء النصيحة .
*********************************************
ALTER PROCEDURE sp_qryReportsInstl
@CustomerName varchar(100)= Null,
@CustomerNo bigint= Null,
@BranchNo int = Null ,
@MorNo bigint = Null ,
@ChequeDueDateFrom datetime= Null,--'01-01-1980',
@ChequeDueDateTo datetime = Null,--'01-01-2050',
@RemainingAmountFrom float = 0,
@RemainingAmountTo float = 5000000000,
@MorabCatCode int = Null ,
@ChequeStatus int = Null,
@ShowResutlt int = 1,
@TotalRemainingAmount float OUTPUT,
@CountRec float OUTPUT
AS
Declare @strWhere varchar(1000)
SELECT @strWhere = 'BranchNo > 0'
if @CustomerName is not Null select @strWhere = @strWhere + ' AND CustomerName like ''%' + @CustomerName + '%'''
--if @CustomerName is not Null select @strWhere = @strWhere + ' AND CustomerName = ''' + @CustomerName + ''''
if @CustomerNo is not Null select @strWhere = @strWhere + ' AND CustomerNo = ' + convert(varchar(20),@CustomerNo)
if @BranchNo is not Null select @strWhere = @strWhere + ' AND BranchNo =' + convert(varchar(4),@BranchNo)
if @MorNo is not Null select @strWhere = @strWhere + ' AND MorNo =' + @MorNo
if @MorabCatCode is not Null select @strWhere = @strWhere + ' AND MorabCatCode =' + convert(varchar(4),@MorabCatCode)
if @ChequeDueDateFrom is not Null select @strWhere = @strWhere + ' AND ChequeDueDate >=''' + Convert(varchar(25),@ChequeDueDateFrom) +''''
if @ChequeDueDateTo is not Null select @strWhere = @strWhere + ' AND ChequeDueDate <=''' + Convert(varchar(25),@ChequeDueDateTo) +''''
if @RemainingAmountFrom is not Null select @strWhere = @strWhere + ' AND RemainingAmount >=' + Convert(varchar(100),@RemainingAmountFrom)
if @RemainingAmountTo is not Null select @strWhere = @strWhere + ' AND RemainingAmount <=' + Convert(varchar(100),@RemainingAmountTo)
if @ChequeStatus is not Null
Begin
if @ChequeStatus = 2
select @strWhere = @strWhere + ' AND (ChequeStatus = 2 OR ChequeStatus = 5)'
Else
select @strWhere = @strWhere + ' AND ChequeStatus =' + Convert(varchar(100),@ChequeStatus)
End
--select
IF @ShowResutlt = 1
Begin
IF EXISTS(SELECT name FROM sysobjects WHERE name = N'select_qryReportsInstl' AND type = 'U') DROP TABLE select_qryReportsInstl
exec ('select * into select_qryReportsInstl from qryReportsInstl where ' + @strWhere)
select * from select_qryReportsInstl
End
ELSE
IF EXISTS(SELECT name FROM sysobjects WHERE name = N'select_qryReportsInstl' AND type = 'U') Truncate TABLE select_qryReportsInstl
--total
IF EXISTS(SELECT name FROM sysobjects WHERE name = N'total_qryReportsInstl' AND type = 'U') DROP TABLE total_qryReportsInstl
exec ('select Sum(RemainingAmount) as TotalRemainingAmount into total_qryReportsInstl from qryReportsInstl where ' + @strWhere)
select @TotalRemainingAmount = TotalRemainingAmount from total_qryReportsInstl
--count
IF EXISTS(SELECT name FROM sysobjects WHERE name = N'count_qryReportsInstl' AND type = 'U') DROP TABLE count_qryReportsInstl
exec ('select count(RemainingAmount) as CountRec into count_qryReportsInstl from qryReportsInstl where ' + @strWhere)
select @CountRec = CountRec from count_qryReportsInstl
GO