0

我想创建一个这样的 SQL Server 存储过程:

CREATE PROCEDURE dbo.uspGetCharacterID                             
   (@characterName vchar(1000)) 
as            
   SELECT c.charatcer_full    
   FROM CHARACTER c (nolock)      
   WHERE character_full IN (@characterName)      
   ORDER BY C.characterID

从代码中,@charactername我通过 -->'Batman in latest movies', 'Superman in latest movies'

但在代码中它返回零行。

注意:如果我在 SQL 中使用这些字符串运行相同的选择查询,它会成功返回两行。

问题:应该使用哪种数据类型,以便满足要求?

'Varchar''Text'没有工作。

请指导

谢谢

4

1 回答 1

1
CREATE TYPE tp_names AS
        TABLE
        (
        name VARCHAR(1000) NOT NULL
        )

GO

CREATE PROCEDURE
        uspGetCharacterID (@names tp_names READONLY)
AS
        SELECT  c.character_full    
        FROM    CHARACTER c
        WHERE   character_full IN
                (
                SELECT  name
                FROM    @names
                )
        ORDER BY
                characterID

GO

DECLARE @names tp_names

INSERT
INTO    @names
VALUES
        ('Batman in latest movies'),
        ('Superman in latest movies')

EXEC    uspGetCharacterID
                @names = @names
于 2012-06-01T06:45:06.420 回答