SQL Server splits and inserts a specific string. SQL Server
This example describes how SQL Server Splits a specific string and inserts it. We will share this with you for your reference. The details are as follows:
-- Cyclically execute the add operation declare @ idx as intWhile Len (@ UserList)> 0 Begin Set @ idx = Charindex (',', @ UserList ); -- only one data item, If @ idx = 0 and Len (@ UserList)> 0 BeginInsert Into BIS_MsgCenterInfo (ID, MsgID, UserID, [State]) Values (Newid (), @ ID, @ UserList, 0); Break; End -- If @ idx> 1 BeginInsert Into BIS_MsgCenterInfo (ID, MsgID, UserID, [State]) Values (Newid (), @ ID, left (@ UserList, @ idx-1), 0); Set @ UserList = right (@ UserList, Len (@ UserList)-@ idx ); end Else Set @ UserList = right (@ UserList, Len (@ UserList)-@ idx); End
I hope this article will help you design SQL Server database programs.