本文實(shí)例講述了SQL Server實(shí)現(xiàn)將特定字符串拆分并進(jìn)行插入操作的方法。分享給大家供大家參考,具體如下:
--循環(huán)執(zhí)行添加操作 declare @idx as int While Len(@UserList) > 0 Begin Set @idx = Charindex(',', @UserList); --只有一條數(shù)據(jù) If @idx = 0 and Len(@UserList) > 0 Begin Insert Into BIS_MsgCenterInfo(ID,MsgID,UserID,[State])Values(Newid(),@ID,@UserList,0); Break; End --多條數(shù)據(jù) If @idx > 1 Begin Insert 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
希望本文所述對(duì)大家SQL Server數(shù)據(jù)庫程序設(shè)計(jì)有所幫助。
標(biāo)簽:池州 濱州 東營 文山 黃山 大同 來賓 新鄉(xiāng)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQL Server實(shí)現(xiàn)將特定字符串拆分并進(jìn)行插入操作的方法》,本文關(guān)鍵詞 SQL,Server,實(shí),現(xiàn)將,特定,字符串,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。