Sqlserver
 sql >> база данни >  >> RDS >> Sqlserver

Не може да предаде входни параметри към съхранена процедура

Опитайте този -

CREATE PROCEDURE [dbo].[tp_SelectTransactionHistorySearch] 
(
    @OffSetRowNo INT,
    @FetchRowNo INT,
    @StatusSelection NVARCHAR(MAX),
    @isReviewed BIT,
    @ProjectCaseNumber VARCHAR(MAX),
    @CostPageNumber VARCHAR(MAX),
    @TransactionTypeChange VARCHAR(MAX),
    @DescriptionChange VARCHAR(MAX),
    @TrasactionCreateOnBeginDate DATE,
    @TransactionCreatedOnEndDate DATE,
    @TransactionUpdatedOnBeginDate DATE,
    @TransactionUpdateOnEndDate DATE,
    @ItemID VARCHAR(MAX)
)
AS
    SELECT TH.TransactionID
        ,  TH.IsReviewed
        ,  TH.ItemID
        ,  TH.CostPageNumber
        ,  TH.Comments
        ,  TH.CreatedBy
        ,  TH.CreatedDateTime
        ,  TH.UpdatedBy
        ,  TH.UpdatedDateTime
        ,  TH.TransactionDescription
        ,  TH.TransactionTypeID
        ,  IAccrualByItem.PROJCASE
        ,  IAccrualByItem.USTSTAT AS TransactionStatusID
        ,  TStatType.Name AS TransactionStatusTypeName
        ,  TStatType.[description] AS TransactionStatusTypeDescription
        ,  TType.Name AS TransactionTypeName
        ,  TType.[description] AS TransactionTypeDescription
        ,  COUNT(*) OVER () AS TotalCount
    FROM TransactionHistory AS TH
    JOIN TRVMVSDDVW001.INTERFACE_Files.dbo.DBATUSTA AS IAccrualByItem ON TH.TransactionID = CAST(IAccrualByItem.USTTRNNBR AS INT)
    LEFT JOIN dbo.TransctionStatusType AS TStatType ON TStatType.TransactionStatusTypeID= IAccrualByItem.USTSTAT
    LEFT JOIN dbo.TransactionType AS TType ON TType.TransactionTypeID = CAST(TH.TransactionTypeID AS INT)
    WHERE TStatType.Name = @StatusSelection
        AND TH.IsReviewed = @isReviewed
        AND IAccrualByItem.PROJCASE = @ProjectCaseNumber
        AND TH.CostPageNumber = @CostPageNumber
        AND TH.TransactionDescription = @TransactionTypeChange
        AND TType.[description] = @DescriptionChange
        AND TH.CreatedDateTime BETWEEN @TrasactionCreateOnBeginDate AND @TransactionCreatedOnEndDate
        AND TH.UpdatedDateTime BETWEEN @TransactionUpdatedOnBeginDate AND @TransactionUpdateOnEndDate
        AND TH.StatusID = 1
    GROUP BY
          TH.TransactionID
        , TH.IsReviewed
        , TH.ItemID
        , TH.CostPageNumber
        , TH.Comments
        , TH.CreatedBy
        , TH.CreatedDateTime
        , TH.UpdatedBy
        , TH.UpdatedDateTime
        , TH.TransactionDescription
        , TH.TransactionTypeID
        , IAccrualByItem.PROJCASE
        , TransactionStatusID
        , TStatType.Name
        , TStatType.[description]
        , TType.Name
        , TType.[description]
    ORDER BY 
          TH.TransactionID
        , TH.ItemID
        , TH.CostPageNumber
    OFFSET (@OffSetRowNo - 1) * @FetchRowNo ROWS FETCH NEXT @FetchRowNo ROWS ONLY

Актуализация #1:

Задайте тази опция, преди да изпълните вашата заявка -

SET DATEFORMAT dmy

или, по-предпочитано, използвайте ISO формат yyyymmdd -

EXEC @return_value = [dbo].[tp_SelectTransactionHistorySearch]
    ...
    @TrasactionCreateOnBeginDate = '20130310',
    @TransactionCreatedOnEndDate = '20132003',
    @TransactionUpdatedOnBeginDate = '20130520',
    @TransactionUpdateOnEndDate = '20130604',
    @ItemID = NULL

Актуализация №2:

DECLARE @temp TABLE
(
    string VARCHAR(10)
)

SET DATEFORMAT dmy 

INSERT INTO @temp (string)
VALUES 
    ('10-03-2013'),
    ('20-03-2013'),
    ('20-05-2013'),
    ('04-06-2013')

SELECT CAST(string AS DATE) 
FROM @temp


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Задействане на вмъкване на стари стойности - стойности, които са актуализирани

  2. ExecuteScalar хвърля NullReferenceException

  3. Конфигурации с обхват на базата данни на SQL Server и автоматична корекция на план

  4. .NET 4:Как да конфигурирате EDMX файл в друг сборник в Web.Config

  5. Текстът е съкратен или един или повече знаци не са съвпадали в целевата кодова страница при импортиране от Excel файл