1
我以sp_executesql存儲過程:趕上sp_executesql的表結果
USE [databasedevelopment]
GO
/****** Object: StoredProcedure [dbo].[SearchPaymentDev] Script Date: 06/03/2013 16:42:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[SearchPaymentDev]
@PayAccountin as varchar(10),
@PayCustNamein as varchar(30),
@PayAmountin as int,
@PayAmountPaidin as int,
@PayResponsein as char (2),
@PayRefNoin as varchar (120),
@PayScreenTextin as varchar (100),
@PayReceiptTextin as varchar (350),
@PayDatetimein as varchar(50),
@PayBankCodein as varchar (6)
AS
Set NoCount ON
Declare @SQLQuery AS NVarchar(4000)
Declare @ParamDefinition AS NVarchar(2000)
Set @SQLQuery = 'Select * From payment where PayId is not null '
If @PayAccountin Is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayAccount LIKE ''%'' + @PayAccountin + ''%'')'
If @PayCustNamein Is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayCustName LIKE ''%'' + @PayCustNamein + ''%'')'
If @PayAmountin Is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayAmount LIKE ''%'' + @PayAmountin + ''%'')'
If @PayAmountPaidin Is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayAmountPaid LIKE ''%'' + @PayAmountPaidin + ''%'')'
If @PayResponsein is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayResponse LIKE ''%'' + @PayResponsein + ''%'')'
If @PayRefNoin is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayRefNo LIKE ''%'' + @PayRefNoin + ''%'')'
If @PayBankCodein is Not Null
Set @SQLQuery = @SQLQuery + ' And (PayBankCode LIKE ''%'' + @PayAccountin + ''%'')'
If @PayDatetimein is Not Null
Set @SQLQuery = @SQLQuery + ' And (cast(PayDatetime as date) = (select convert(date , @PayDatetimein , 103)))'
Set @ParamDefinition =
'@PayAccountin as varchar(10),
@PayCustNamein as varchar(30),
@PayAmountin as int,
@PayAmountPaidin as int,
@PayResponsein as char (2),
@PayRefNoin as varchar (120),
@PayBankCodein as varchar (6),
@PayDatetimein as varchar(50)'
Execute sp_Executesql
@SQLQuery,
@ParamDefinition,
@PayAccountin,
@PayCustNamein,
@PayAmountin,
@PayAmountPaidin,
@PayResponsein,
@PayRefNoin,
@PayBankCodein,
@PayDatetimein
If @@ERROR <> 0 GoTo ErrorHandler
Set NoCount OFF
Return(0)
ErrorHandler:
Return(@@ERROR)
現在我用vb.net代碼存儲過程的背後,並獲得數據,數據表和工藝上VB.net代碼背後。
但現在我想要獲得表結果查詢和進度到相同的stored procedure
來更改一些字段值,是否有可能在存儲過程中首先捕獲表,更改該值並給出要使用的輸出在vb.net上?
感謝您的幫助。
幾乎重複:http://stackoverflow.com/questions/803211/how-to-get-sp-executesql-result-into-a-variable –
@DavidBrabant燁,差不多。我已經嘗試了輸出方法,但它只給出我最高1的值,我想要所有的行:) – Sabilv