不允许嵌套存储过程从数据类型datetime到int的隐式转换

时间:2014-05-01 06:17:38

标签: sql sql-server stored-procedures

为什么我为SP呼叫另一个SP而收到此错误。如果我调用SP目录它就可以了。

  

Msg 257,Level 16,State 3,Procedure TEST1,Line 25
  不允许从数据类型datetime到int的隐式转换。使用CONVERT函数运行此查询。

SP1 - > SP

ALTER PROCEDURE [TEST].[TEST1]
    @EventId INT = NULL,
    @MemberId INT = NULL,
    @Type INT = NULL,
    @Scheduled BIT = 0,
    @DivisionId INT = NULL,
    @DivisionTeamId INT = NULL,
    @Date DATETIME = NULL,
    @GymCourtId INT = NULL
AS

BEGIN     设置NOCOUNT ON;     SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

CREATE TABLE #GridGames (
    [Id] [int] NOT NULL,
    [Number] [int] NULL,
    [Round] [int] NULL,
    [GameType] [int] NULL,
.
.
.
.
INSERT INTO #GridGames 
EXEC [TEST].[TEST] @EventId, @MemberId, @Type, @Scheduled, @DivisionId, @DivisionTeamId, @Date, @GymCourtId

SP

ALTER PROCEDURE [TEST].[TEST]
    @EventId INT = NULL,
    @MemberId INT = NULL,
    @Type INT = NULL,
    @Scheduled BIT = 0,
    @DivisionId INT = NULL,
    @DivisionTeamId INT = NULL,
    @Date DATETIME = NULL,
    @GymCourtId INT = NULL
AS
BEGIN
    DECLARE @DayAhead DATETIME;

    IF(@Date IS NOT NULL)
    BEGIN
        SET @DayAhead = DATEADD (DAY , 1 , @Date);
    END

SELECT
        game.Id,
        game.[Type] AS GameType,
        game.[Date], 

更新

第25行指向嵌套存储过程中的game.[Date],但这是一个日期时间为null的类型,我的临时表也有,那给出了什么?

1 个答案:

答案 0 :(得分:4)

找出原因,这是因为我在内部SP select语句中的参数顺序与临时表顺序不匹配。