不懂 SQL 过程错误 [英] Don't Understand SQL Procedure Error

查看:30
本文介绍了不懂 SQL 过程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主表Repairs"和一个明细表RepairDetails"我正在尝试编写一个程序,当我从我的应用程序发送适当的参数时更新这两个表.这是我的 SQL:

I have a master table "Repairs" and a detail table "RepairDetails" I am trying to write a procedure to update both tables when I send the appropriate parameters from my application. Here is my SQL:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UpdateRepair]
    @RepairID bigint,
    @TypeID bigint = NULL,
    @Directions nvarchar(3000) = NULL,
    @NewDetails NewDetails READONLY
AS
BEGIN
    SET NOCOUNT ON;
    UPDATE Repairs
    SET
        TypeID = ISNULL(@TypeID, TypeID),
        Directions = ISNULL(@Directions, Directions),
        LastUpdate = SYSDATETIME()
    WHERE RepairID = @RepairID;
    IF @NewDetails IS NOT NULL UpdateRepairDetails;
END

其中NewDetails"是用户定义的表类型,UpdateRepairDetails"是一个不同的存储过程,它以@RepairID 和@NewDetails 作为参数.

where "NewDetails" is a User-defined table type and "UpdateRepairDetails" is a different stored procedure that takes @RepairID and @NewDetails as parameters.

我有一个错误和一个问题.错误信息是:

I have an error and a question. The error message is:

Must declare the scalar variable "@NewDetails"

我不明白,因为它是定义的.

which I don't understand because it is defined.

我的问题是:参数@RepairID"和@NewDetails"是否会自动传递给UpdateRepairDetails"过程.如果不是,那么实现此目的的正确方法是什么?

And my question is: will the parameters "@RepairID" and "@NewDetails" get automatically passed to the "UpdateRepairDetails" procedure. If not, what is the proper approach to accomplish this?

推荐答案

不能将 NULL 分配给表变量.因此,您无法检查表变量是否为 NULL.

You cannot assign NULL to a table variable. Hence you can't check whether a table variable is NULL.

第二:没有.您应该按如下方式调用:

Second: no. You should call as follows:

EXEC UpdateRepairDetails @RepairID, @NewDetails;

这篇关于不懂 SQL 过程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆