I have excuted store procedure in both SQL Server 2000 and SQL Server 2008 like this:
DECLARE @mobile varchar(20)
BEGIN
SET @mobile = (select Mobile from NodesMobile where nodeId = 1) //@mobile will return '123;456'
INSERT INTO dbo.SMS([sSub], [sContent])
SELECT *,'sms_content' from dbo.splitstring(@mobile)
END
in this, SELECT *,'sms_content' from dbo.splitstring(@mobile) will return:
Mobile Content
123 sms_content
456 sms_content
In SQL server 2000, it is successfully insert 2 rows to dbo.SMS:
Id sSub sContent
1 123 sms_content
2 456 sms_content
But it is show error in SQL Server 2008:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
I dont know why???
EDIT: dbo.splitstring is a function for split string by ';'
CREATE FUNCTION [dbo].[splitstring] ( @stringToSplit nvarchar(255) )
RETURNS
@returnList TABLE ([Name] [nvarchar] (500))
AS
BEGIN
DECLARE @name NVARCHAR(255)
DECLARE @pos INT
WHILE CHARINDEX(';', @stringToSplit) > 0
BEGIN
SELECT @pos = CHARINDEX(';', @stringToSplit)
SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1)
INSERT INTO @returnList
SELECT @name
SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)-@pos)
END
INSERT INTO @returnList
SELECT @stringToSplit
RETURN
END
2条答案
按热度按时间iecba09b1#
Your date might be different, try
limit
yoursubquery
results.tct7dpnv2#
The problem is not in string_split, but rather in the mobile part:
SET @mobile = (select Mobile from NodesMobile where nodeId = 1)
This can never succeed if you have more than one match from NodesMobile table.
This is how it looks on SQL Server 2000:
Outputs:
I'm guessing something else is going on