SELECT
tblPropertyLocationSubCategory.PLSId
, tblPropertyLocationSubCategory.PLSName
, tblPropertyLocationSubCategory.PLCId
, tblPropertyLocationCategory.PLCName
FROM
tblPropertyLocationSubCategory
INNER JOIN tblPropertyLocationCategory
ON tblPropertyLocationSubCategory.PLCId = tblPropertyLocationCategory.PLCId
WHERE
PLSId in(select Item from [dbo].[SplitString](@sPLSName,','))
答案 0 :(得分:2)
首先创建函数,
CREATE FUNCTION SplitString
(
@Input NVARCHAR(MAX),
@Character CHAR(1)
)
RETURNS @Output TABLE (
Item NVARCHAR(1000)
)
AS
BEGIN
DECLARE @StartIndex INT, @EndIndex INT
SET @StartIndex = 1
IF SUBSTRING(@Input, LEN(@Input) - 1, LEN(@Input)) <> @Character
BEGIN
SET @Input = @Input + @Character
END
WHILE CHARINDEX(@Character, @Input) > 0
BEGIN
SET @EndIndex = CHARINDEX(@Character, @Input)
INSERT INTO @Output(Item)
SELECT SUBSTRING(@Input, @StartIndex, @EndIndex - 1)
SET @Input = SUBSTRING(@Input, @EndIndex + 1, LEN(@Input))
END
RETURN
END
然后执行您的查询,它将起作用。