日期:2014-05-17 浏览次数:20501 次
CREATE PROCEDURE PopFirstWord
@SourceString NVARCHAR(4000) = NULL OUTPUT,
@FirstWord NVARCHAR(4000) = NULL OUTPUT
AS
SET NOCOUNT ON
-- Procedure accepts a comma delimited string as the first parameter
-- Procedure outputs the first word in the second parameter
-- Procedure outputs the remainder of the delimeted string in the first parameter
-- Procedure yields the length of the First Word as the return value
DECLARE @Oldword NVARCHAR(4000)
DECLARE @Length INT
DECLARE @CommaLocation INT
SELECT @Oldword = @SourceString
IF NOT @Oldword IS NULL
BEGIN
SELECT @CommaLocation = CHARINDEX('#',@Oldword)
SELECT @Length = DATALENGTH(@Oldword)
IF @CommaLocation = 0
BEGIN
SELECT @FirstWord = @Oldword
SELECT @SourceString = NULL
RETURN @Length
END
SELECT @FirstWord = SUBSTRING(@Oldword, 1, @CommaLocation -1)
SELECT @SourceString = SUBSTRING(@Oldword, @CommaLocation + 1, @Length - @CommaLocation)
RETURN @Length - @CommaLocation
END
RETURN 0
------------------------------------------------
GO
CREATE PROCEDURE InsertToExpertList
@ExpIDList NVARCHAR(4000),
@EIdList NVARCHAR(4000),
@CMaker varchar(50)
AS
SET NOCOUNT ON
Begin TRAN
DECLARE @Length INT
DECLARE @FirstExpID NVARCHAR(4000)
DECLARE @ExpID INT
SELECT @Length = DATALENGTH(@ExpIDList)
WHILE @Length > 0