1
我有TSQL中的表值函數,如果我傳遞一個字符串,但如果我傳遞一個varchar,則不會有效。TSQL表值函數參數不同的行爲,如果參數變量
例如,這個工程:
SELECT * from [dbo].[SplitString]('ta;aa;qq', ';')
這不起作用:
declare @invarchar as varchar
set @invarchar = 'ta;aa;qq'
SELECT * from [dbo].[SplitString](@invarchar, ';')
如果你好奇的功能:
CREATE FUNCTION [dbo].[SplitString]
(
@List NVARCHAR(MAX),
@Delim VARCHAR(255)
)
RETURNS TABLE
AS
RETURN (SELECT [Value] FROM
(
SELECT
[Value] = LTRIM(RTRIM(SUBSTRING(@List, [Number],
CHARINDEX(@Delim, @List + @Delim, [Number]) - [Number])))
FROM (SELECT Number = ROW_NUMBER() OVER (ORDER BY name)
FROM sys.all_objects) AS x
WHERE Number <= LEN(@List)
AND SUBSTRING(@Delim + @List, [Number], LEN(@Delim)) = @Delim
) AS y
);
GO
我有與多個表值函數相同的結果,所以我想我的問題是我從錯誤的變量中調用它的方式。我怎樣才能使用一個變量,仍然有相同的輸出?