1

我想准备一个需要 2 个参数(Int,string)的过程如果表中存在某些行,我将得到 @dane = 1; 最后我想选择@dane,但我的程序不好。我不能使用 return @dane。

    USE [SS]
    GO

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    CREATE PROCEDURE [permission].[CheckSkill] 
(
    @SkillId INT, -- Identyfikator użytkownika 
    @Description NVARCHAR(100) = NULL
)
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @dana as int
    SET @dana = 0

    -- this is redundant:
    --SET @Description = RTRIM(LTRIM(ISNULL(@Description,'')))

    IF EXISTS (SELECT * FROM permission.UserXSkill Where permission.UserXSkill.SkillId = @SkillId)
    BEGIN
      SET @dana = 1;
    END

    SELECT @dana AS ID;
END
GO

主题 [关闭] 感谢您的帮助。

4

1 回答 1

2

为变量赋值时需要使用SETor 。SELECT

EXISTS似乎满足您所在IF街区的要求

@Description参数未使用且是多余的

USE [SS]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [permission].[CheckSkill] 
(
    @SkillId INT, -- Identyfikator użytkownika 
    @Description NVARCHAR(100) = NULL,

)
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @dana as int
    SET @dana = 0

    -- this is redundant:
    --SET @Description = RTRIM(LTRIM(ISNULL(@Description,'')))

    IF EXISTS (SELECT * FROM permission.UserXSkill Where permission.UserXSkill = @SkillId)
    BEGIN
      SET @dana = 1;
    END

    SELECT @dana AS ID;
END
GO
于 2012-10-31T08:22:01.340 回答