これを試すことができます:
create table tSqlStrings (sText nvarchar(1000))
insert tSqlStrings values('''dsasdasdsd''+''ewewewew''+''45454545''+(avg(''uuuuuuu''))')
create table tResults (
sColumn1 nvarchar(1000)
,sColumn2 nvarchar(1000)
,sColumn3 nvarchar(1000)
,sColumn4 nvarchar(1000)
)
と
DELETE tResults
DECLARE @sText nvarchar(1000) = (
SELECT
sText
FROM
tSqlStrings
)
DECLARE @lBegin int = CHARINDEX('''',@sText)
DECLARE @lEnd int = charindex('''',
substring(@sText,
CHARINDEX('''',@sText)+1,
len(@sText)))
DECLARE @sText0 nvarchar(1000)
DECLARE @sColumn1 nvarchar(1000)
DECLARE @sColumn2 nvarchar(1000)
DECLARE @sColumn3 nvarchar(1000)
DECLARE @sColumn4 nvarchar(1000)
DECLARE @iCnt int = 1
while @iCnt<=4
--(0<len(@sText) and 0<@lBegin and 0<@lEnd)
BEGIN
SET @sText0 = substring(@sText,@lBegin+1,@lEnd-2)
IF @iCnt=1 begin SET @sColumn1=@sText0 end
IF @iCnt=2 begin SET @sColumn2=@sText0 end
IF @iCnt=3 begin SET @sColumn3=@sText0 end
IF @iCnt=4 begin SET @sColumn4=@sText0 end
set @sText = substring(@sText,@lBegin + @lEnd+2,len(@sText))
SET @lBegin = CHARINDEX('''',@sText)
SET @lEnd = charindex('''',
substring(@sText,
CHARINDEX('''',@sText)+1,
len(@sText)))
SET @iCnt = @iCnt+1
END
INSERT
tResults (sColumn1,sColumn2,sColumn3,sColumn4)
VALUES (@sColumn1,@sColumn2,@sColumn3,@sColumn4)
SELECT * FROM tResults
SQLフィドルで