根据特定的间隔/字符

时间:2017-06-02 12:58:11

标签: sql sql-server tsql sql-server-2012

我有以下字符串字符串:

'TransID, Convert(VarChar(250), [TPSYN]) AS [TPSYN], Convert(VarChar(250), [SureFitYN]) AS [SureFitYN], Convert(VarChar(250), [AccountNbr]) AS [AccountNbr], Convert(VarChar(250), [Account Name]) AS [Account Name], Convert(VarChar(250), [EffectiveDate]) AS [EffectiveDate], Convert(VarChar(250), [IM]) AS [IM], Convert(VarChar(250), [RevisionDate]) AS [RevisionDate], Convert(VarChar(250), [AccountAddress]) AS [AccountAddress], Convert(VarChar(250), [LSOCode]) AS [LSOCode], Convert(VarChar(250), [ASONonASOBoth]) AS [ASONonASOBoth], Convert(VarChar(250), [MedicalYN]) AS [MedicalYN], Convert(VarChar(250), [NonManagedCareYN]) AS [NonManagedCareYN], Convert(VarChar(250), [ManagedCareYN]) AS [ManagedCareYN], Convert(VarChar(250), [HRAYN]) AS [HRAYN], Convert(VarChar(250), [MedHRAYN]) AS [MedHRAYN], Convert(VarChar(250), [LPHRAYN]) AS [LPHRAYN], Convert(VarChar(250), [HealthyFutYN]) AS [HealthyFutYN], Convert(VarChar(250), [HAHRAYN]) AS [HAHRAYN], Convert(VarChar(250), [HSAYN]) AS [HSAYN], Convert(VarChar(25
0), [FSAHealthCare]) AS [FSAHealthCare], Convert(VarChar(250), [FSADependentCare]) AS [FSADependentCare], Convert(VarChar(250), [DentalYN]) AS [DentalYN], Convert(VarChar(250), [TaftHartley]) AS [TaftHartley], Convert(VarChar(250), [ParameterComments]) AS [ParameterComments], Convert(VarChar(250), [MLRAvgLivesNumber]) AS [MLRAvgLivesNumber], Convert(VarChar(250), [MLRAvgLivesRptYear]) AS [MLRAvgLivesRptYear], Convert(VarChar(250), [MLRContact]) AS [MLRContact], Convert(VarChar(250), [MLRContactAddress1]) AS [MLRContactAddress1], Convert(VarChar(250), [MLRContactAddress2]) AS [MLRContactAddress2], Convert(VarChar(250), [MLRContactCity]) AS [MLRContactCity], Convert(VarChar(250), [MLRContactState]) AS [MLRContactState], Convert(VarChar(250), [MLRContactZip]) AS [MLRContactZip], Convert(VarChar(250), [HealthRiskAssessment]) AS [HealthRiskAssessment], Convert(VarChar(250), [ErisaYN]) AS [ErisaYN], Convert(VarChar(250), [ErisaPlanName]) AS [ErisaPlanName], Convert(VarChar(250), [ErisaPlanNumber]) AS [ErisaPlanNum
ber], Convert(VarChar(250), [ErisaPlanEndsMM]) AS [ErisaPlanEndsMM], Convert(VarChar(250), [ErisaPlanEndsDD]) AS [ErisaPlanEndsDD], Convert(VarChar(250), [ErisaAdministrator]) AS [ErisaAdministrator], Convert(VarChar(250), [ErisaClaimAdministrator]) AS [ErisaClaimAdministrator], Convert(VarChar(250), [ErisaCost]) AS [ErisaCost], Convert(VarChar(250), [ErisaEOB]) AS [ErisaEOB], Convert(VarChar(250), [ErisaEOBName]) AS [ErisaEOBName], Convert(VarChar(250), [ErisaEOBAddress1]) AS [ErisaEOBAddress1], Convert(VarChar(250), [ErisaEOBAddress2]) AS [ErisaEOBAddress2], Convert(VarChar(250), [ErisaEOBCity]) AS [ErisaEOBCity], Convert(VarChar(250), [ErisaEOBState]) AS [ErisaEOBState], Convert(VarChar(250), [ErisaEOBZip]) AS [ErisaEOBZip], Convert(VarChar(250), [ErisaEOBPhone]) AS [ErisaEOBPhone], Convert(VarChar(250), [ErisaPAName]) AS [ErisaPAName], Convert(VarChar(250), [ErisaPAAddress1]) AS [ErisaPAAddress1], Convert(VarChar(250), [ErisaPAAddress2]) AS [ErisaPAAddress2], Convert(VarChar(250), [ErisaPACity]) AS [Eris
aPACity], Convert(VarChar(250), [ErisaPAState]) AS [ErisaPAState], Convert(VarChar(250), [ErisaPAZip]) AS [ErisaPAZip], Convert(VarChar(250), [ErisaPAPhone]) AS [ErisaPAPhone], Convert(VarChar(250), [ErisaLAName]) AS [ErisaLAName], Convert(VarChar(250), [ErisaLAAddress1]) AS [ErisaLAAddress1], Convert(VarChar(250), [ErisaLAAddress2]) AS [ErisaLAAddress2], Convert(VarChar(250), [ErisaLACity]) AS [ErisaLACity], Convert(VarChar(250), [ErisaLAState]) AS [ErisaLAState], Convert(VarChar(250), [ErisaLAZip]) AS [ErisaLAZip], Convert(VarChar(250), [ErisaLAPhone]) AS [ErisaLAPhone], Convert(VarChar(250), [ERISAComments]) AS [ERISAComments], Convert(VarChar(250), [CSNApproval]) AS [CSNApproval], Convert(VarChar(250), [CSNPPO]) AS [CSNPPO], Convert(VarChar(250), [CSNOAP]) AS [CSNOAP], Convert(VarChar(250), [CSNSupplemental]) AS [CSNSupplemental], Convert(VarChar(250), [CSNReplacement]) AS [CSNReplacement], Convert(VarChar(250), [CSNType]) AS [CSNType], Convert(VarChar(250), [CSNNBNIL915]) AS [CSNNBNIL915], Convert(VarCh
ar(250), [CSNNBNPA910]) AS [CSNNBNPA910], Convert(VarChar(250), [CSNNBNPA911]) AS [CSNNBNPA911], Convert(VarChar(250), [CSNNBNFL918]) AS [CSNNBNFL918], Convert(VarChar(250), [CSNNBNCA915]) AS [CSNNBNCA915], Convert(VarChar(250), [CSNNBNMA904]) AS [CSNNBNMA904], Convert(VarChar(250), [CSNOwnLogo]) AS [CSNOwnLogo], Convert(VarChar(250), [CSNNBNAllBranches]) AS [CSNNBNAllBranches], Convert(VarChar(250), [CSNNBNBranchComment]) AS [CSNNBNBranchComment], Convert(VarChar(250), [ASOStopLoss]) AS [ASOStopLoss], Convert(VarChar(250), [ASOCigna]) AS [ASOCigna], Convert(VarChar(250), [ASOThirdParty]) AS [ASOThirdParty], Convert(VarChar(250), [ASORetirees]) AS [ASORetirees], Convert(VarChar(250), [ISOStopLoss]) AS [ISOStopLoss], Convert(VarChar(250), [ISOCigna]) AS [ISOCigna], Convert(VarChar(250), [ISOThirdParty]) AS [ISOThirdParty], Convert(VarChar(250), [ISORetirees]) AS [ISORetirees], Convert(VarChar(250), [ASOReimbCigna]) AS [ASOReimbCigna], Convert(VarChar(250), [ASOReimbOther]) AS [ASOReimbOther]'

我需要做的是插入换行符,以便没有行超过950个字符,但我需要在字段名称的末尾插入这些符号。所以,我需要做的是从字符950开始并向后工作,直到找到"],"的第一个实例。我需要在那里插入换行符,然后向前计数950个字符并再次向后工作,直到我点击"],"的第一个实例。泡沫,冲洗,重复。

结果字符串应该看起来像这样(除非我算错了):

TransID, Convert(VarChar(250), [TPSYN]) AS [TPSYN], Convert(VarChar(250), [SureFitYN]) AS [SureFitYN], Convert(VarChar(250), [AccountNbr]) AS [AccountNbr], Convert(VarChar(250), [Account Name]) AS [Account Name], Convert(VarChar(250), [EffectiveDate]) AS [EffectiveDate], Convert(VarChar(250), [IM]) AS [IM], Convert(VarChar(250), [RevisionDate]) AS [RevisionDate], Convert(VarChar(250), [AccountAddress]) AS [AccountAddress], Convert(VarChar(250), [LSOCode]) AS [LSOCode], Convert(VarChar(250), [ASONonASOBoth]) AS [ASONonASOBoth], Convert(VarChar(250), [MedicalYN]) AS [MedicalYN], Convert(VarChar(250), [NonManagedCareYN]) AS [NonManagedCareYN], Convert(VarChar(250), [ManagedCareYN]) AS [ManagedCareYN], Convert(VarChar(250), [HRAYN]) AS [HRAYN], Convert(VarChar(250), [MedHRAYN]) AS [MedHRAYN], Convert(VarChar(250), [LPHRAYN]) AS [LPHRAYN], Convert(VarChar(250), [HealthyFutYN]) AS [HealthyFutYN], Convert(VarChar(250), [HAHRAYN]) AS [HAHRAYN], 
Convert(VarChar(250), [HSAYN]) AS [HSAYN], Convert(VarChar(250), [FSAHealthCare]) AS [FSAHealthCare], Convert(VarChar(250), [FSADependentCare]) AS [FSADependentCare], Convert(VarChar(250), [DentalYN]) AS [DentalYN], Convert(VarChar(250), [TaftHartley]) AS [TaftHartley], Convert(VarChar(250), [ParameterComments]) AS [ParameterComments], Convert(VarChar(250), [MLRAvgLivesNumber]) AS [MLRAvgLivesNumber], Convert(VarChar(250), [MLRAvgLivesRptYear]) AS [MLRAvgLivesRptYear], Convert(VarChar(250), [MLRContact]) AS [MLRContact], Convert(VarChar(250), [MLRContactAddress1]) AS [MLRContactAddress1], Convert(VarChar(250), [MLRContactAddress2]) AS [MLRContactAddress2], Convert(VarChar(250), [MLRContactCity]) AS [MLRContactCity], Convert(VarChar(250), [MLRContactState]) AS [MLRContactState], Convert(VarChar(250), [MLRContactZip]) AS [MLRContactZip], Convert(VarChar(250), [HealthRiskAssessment]) AS [HealthRiskAssessment], Convert(VarChar(250), [ErisaYN]) AS [ErisaYN], 
Convert(VarChar(250), [ErisaPlanName]) AS [ErisaPlanName], Convert(VarChar(250), [ErisaPlanNumber]) AS [ErisaPlanNumber], Convert(VarChar(250), [ErisaPlanEndsMM]) AS [ErisaPlanEndsMM], Convert(VarChar(250), [ErisaPlanEndsDD]) AS [ErisaPlanEndsDD], Convert(VarChar(250), [ErisaAdministrator]) AS [ErisaAdministrator], Convert(VarChar(250), [ErisaClaimAdministrator]) AS [ErisaClaimAdministrator], Convert(VarChar(250), [ErisaCost]) AS [ErisaCost], Convert(VarChar(250), [ErisaEOB]) AS [ErisaEOB], Convert(VarChar(250), [ErisaEOBName]) AS [ErisaEOBName], Convert(VarChar(250), [ErisaEOBAddress1]) AS [ErisaEOBAddress1], Convert(VarChar(250), [ErisaEOBAddress2]) AS [ErisaEOBAddress2], Convert(VarChar(250), [ErisaEOBCity]) AS [ErisaEOBCity], Convert(VarChar(250), [ErisaEOBState]) AS [ErisaEOBState], Convert(VarChar(250), [ErisaEOBZip]) AS [ErisaEOBZip], Convert(VarChar(250), [ErisaEOBPhone]) AS [ErisaEOBPhone], Convert(VarChar(250), [ErisaPAName]) AS [ErisaPAName], 
Convert(VarChar(250), [ErisaPAAddress1]) AS [ErisaPAAddress1], Convert(VarChar(250), [ErisaPAAddress2]) AS [ErisaPAAddress2], Convert(VarChar(250), [ErisaPACity]) AS [ErisaPACity], Convert(VarChar(250), [ErisaPAState]) AS [ErisaPAState], Convert(VarChar(250), [ErisaPAZip]) AS [ErisaPAZip], Convert(VarChar(250), [ErisaPAPhone]) AS [ErisaPAPhone], Convert(VarChar(250), [ErisaLAName]) AS [ErisaLAName], Convert(VarChar(250), [ErisaLAAddress1]) AS [ErisaLAAddress1], Convert(VarChar(250), [ErisaLAAddress2]) AS [ErisaLAAddress2], Convert(VarChar(250), [ErisaLACity]) AS [ErisaLACity], Convert(VarChar(250), [ErisaLAState]) AS [ErisaLAState], Convert(VarChar(250), [ErisaLAZip]) AS [ErisaLAZip], Convert(VarChar(250), [ErisaLAPhone]) AS [ErisaLAPhone], Convert(VarChar(250), [ERISAComments]) AS [ERISAComments], Convert(VarChar(250), [CSNApproval]) AS [CSNApproval], Convert(VarChar(250), [CSNPPO]) AS [CSNPPO], Convert(VarChar(250), [CSNOAP]) AS [CSNOAP], 
Convert(VarChar(250), [CSNSupplemental]) AS [CSNSupplemental], Convert(VarChar(250), [CSNReplacement]) AS [CSNReplacement], Convert(VarChar(250), [CSNType]) AS [CSNType], Convert(VarChar(250), [CSNNBNIL915]) AS [CSNNBNIL915], Convert(VarChar(250), [CSNNBNPA910]) AS [CSNNBNPA910], Convert(VarChar(250), [CSNNBNPA911]) AS [CSNNBNPA911], Convert(VarChar(250), [CSNNBNFL918]) AS [CSNNBNFL918], Convert(VarChar(250), [CSNNBNCA915]) AS [CSNNBNCA915], Convert(VarChar(250), [CSNNBNMA904]) AS [CSNNBNMA904], Convert(VarChar(250), [CSNOwnLogo]) AS [CSNOwnLogo], Convert(VarChar(250), [CSNNBNAllBranches]) AS [CSNNBNAllBranches], Convert(VarChar(250), [CSNNBNBranchComment]) AS [CSNNBNBranchComment], Convert(VarChar(250), [ASOStopLoss]) AS [ASOStopLoss], Convert(VarChar(250), [ASOCigna]) AS [ASOCigna], Convert(VarChar(250), [ASOThirdParty]) AS [ASOThirdParty], Convert(VarChar(250), [ASORetirees]) AS [ASORetirees], Convert(VarChar(250), [ISOStopLoss]) AS [ISOStopLoss], 
Convert(VarChar(250), [ISOCigna]) AS [ISOCigna], Convert(VarChar(250), [ISOThirdParty]) AS [ISOThirdParty], Convert(VarChar(250), [ISORetirees]) AS [ISORetirees], Convert(VarChar(250), [ASOReimbCigna]) AS [ASOReimbCigna], Convert(VarChar(250), [ASOReimbOther]) AS [ASOReimbOther]

字符串几乎总是在变化,所以我不能对断点进行硬编码,它必须动态完成。

我知道一点SQL但不足以做到这一点,我甚至不知道从哪里开始。

有人给了我这段代码,但它只是在前950个字符后插入一个换行符:

declare @var nvarchar(max) = 'SELECT TransID, Convert(VarChar(250), [TPSYN]) AS [TPSYN], Convert(VarChar(250), [SureFitYN]) AS [SureFitYN], Convert(VarChar(250), [AccountNbr]) AS [AccountNbr], Convert(VarChar(250), [Account Name]) AS [Account Name], Convert(VarChar(250), [EffectiveDate]) AS [EffectiveDate], Convert(VarChar(250), [IM]) AS [IM], Convert(VarChar(250), [RevisionDate]) AS [RevisionDate], Convert(VarChar(250), [AccountAddress]) AS [AccountAddress], Convert(VarChar(250), [LSOCode]) AS [LSOCode], Convert(VarChar(250), [ASONonASOBoth]) AS [ASONonASOBoth], Convert(VarChar(250), [MedicalYN]) AS [MedicalYN], Convert(VarChar(250), [NonManagedCareYN]) AS [NonManagedCareYN], Convert(VarChar(250), [ManagedCareYN]) AS [ManagedCareYN], Convert(VarChar(250), [HRAYN]) AS [HRAYN], Convert(VarChar(250), [MedHRAYN]) AS [MedHRAYN], Convert(VarChar(250), [LPHRAYN]) AS [LPHRAYN], Convert(VarChar(250), [HealthyFutYN]) AS [HealthyFutYN], Convert(VarChar(250), [HAHRAYN]) AS [HAHRAYN], Convert(VarChar(250), [HSAYN]) AS [HSAYN], Convert(VarChar(25
0), [FSAHealthCare]) AS [FSAHealthCare], Convert(VarChar(250), [FSADependentCare]) AS [FSADependentCare], Convert(VarChar(250), [DentalYN]) AS [DentalYN], Convert(VarChar(250), [TaftHartley]) AS [TaftHartley], Convert(VarChar(250), [ParameterComments]) AS [ParameterComments], Convert(VarChar(250), [MLRAvgLivesNumber]) AS [MLRAvgLivesNumber], Convert(VarChar(250), [MLRAvgLivesRptYear]) AS [MLRAvgLivesRptYear], Convert(VarChar(250), [MLRContact]) AS [MLRContact], Convert(VarChar(250), [MLRContactAddress1]) AS [MLRContactAddress1], Convert(VarChar(250), [MLRContactAddress2]) AS [MLRContactAddress2], Convert(VarChar(250), [MLRContactCity]) AS [MLRContactCity], Convert(VarChar(250), [MLRContactState]) AS [MLRContactState], Convert(VarChar(250), [MLRContactZip]) AS [MLRContactZip], Convert(VarChar(250), [HealthRiskAssessment]) AS [HealthRiskAssessment], Convert(VarChar(250), [ErisaYN]) AS [ErisaYN], Convert(VarChar(250), [ErisaPlanName]) AS [ErisaPlanName], Convert(VarChar(250), [ErisaPlanNumber]) AS [ErisaPlanNum
ber], Convert(VarChar(250), [ErisaPlanEndsMM]) AS [ErisaPlanEndsMM], Convert(VarChar(250), [ErisaPlanEndsDD]) AS [ErisaPlanEndsDD], Convert(VarChar(250), [ErisaAdministrator]) AS [ErisaAdministrator], Convert(VarChar(250), [ErisaClaimAdministrator]) AS [ErisaClaimAdministrator], Convert(VarChar(250), [ErisaCost]) AS [ErisaCost], Convert(VarChar(250), [ErisaEOB]) AS [ErisaEOB], Convert(VarChar(250), [ErisaEOBName]) AS [ErisaEOBName], Convert(VarChar(250), [ErisaEOBAddress1]) AS [ErisaEOBAddress1], Convert(VarChar(250), [ErisaEOBAddress2]) AS [ErisaEOBAddress2], Convert(VarChar(250), [ErisaEOBCity]) AS [ErisaEOBCity], Convert(VarChar(250), [ErisaEOBState]) AS [ErisaEOBState], Convert(VarChar(250), [ErisaEOBZip]) AS [ErisaEOBZip], Convert(VarChar(250), [ErisaEOBPhone]) AS [ErisaEOBPhone], Convert(VarChar(250), [ErisaPAName]) AS [ErisaPAName], Convert(VarChar(250), [ErisaPAAddress1]) AS [ErisaPAAddress1], Convert(VarChar(250), [ErisaPAAddress2]) AS [ErisaPAAddress2], Convert(VarChar(250), [ErisaPACity]) AS [Eris
aPACity], Convert(VarChar(250), [ErisaPAState]) AS [ErisaPAState], Convert(VarChar(250), [ErisaPAZip]) AS [ErisaPAZip], Convert(VarChar(250), [ErisaPAPhone]) AS [ErisaPAPhone], Convert(VarChar(250), [ErisaLAName]) AS [ErisaLAName], Convert(VarChar(250), [ErisaLAAddress1]) AS [ErisaLAAddress1], Convert(VarChar(250), [ErisaLAAddress2]) AS [ErisaLAAddress2], Convert(VarChar(250), [ErisaLACity]) AS [ErisaLACity], Convert(VarChar(250), [ErisaLAState]) AS [ErisaLAState], Convert(VarChar(250), [ErisaLAZip]) AS [ErisaLAZip], Convert(VarChar(250), [ErisaLAPhone]) AS [ErisaLAPhone], Convert(VarChar(250), [ERISAComments]) AS [ERISAComments], Convert(VarChar(250), [CSNApproval]) AS [CSNApproval], Convert(VarChar(250), [CSNPPO]) AS [CSNPPO], Convert(VarChar(250), [CSNOAP]) AS [CSNOAP], Convert(VarChar(250), [CSNSupplemental]) AS [CSNSupplemental], Convert(VarChar(250), [CSNReplacement]) AS [CSNReplacement], Convert(VarChar(250), [CSNType]) AS [CSNType], Convert(VarChar(250), [CSNNBNIL915]) AS [CSNNBNIL915], Convert(VarCh
ar(250), [CSNNBNPA910]) AS [CSNNBNPA910], Convert(VarChar(250), [CSNNBNPA911]) AS [CSNNBNPA911], Convert(VarChar(250), [CSNNBNFL918]) AS [CSNNBNFL918], Convert(VarChar(250), [CSNNBNCA915]) AS [CSNNBNCA915], Convert(VarChar(250), [CSNNBNMA904]) AS [CSNNBNMA904], Convert(VarChar(250), [CSNOwnLogo]) AS [CSNOwnLogo], Convert(VarChar(250), [CSNNBNAllBranches]) AS [CSNNBNAllBranches], Convert(VarChar(250), [CSNNBNBranchComment]) AS [CSNNBNBranchComment], Convert(VarChar(250), [ASOStopLoss]) AS [ASOStopLoss], Convert(VarChar(250), [ASOCigna]) AS [ASOCigna], Convert(VarChar(250), [ASOThirdParty]) AS [ASOThirdParty], Convert(VarChar(250), [ASORetirees]) AS [ASORetirees], Convert(VarChar(250), [ISOStopLoss]) AS [ISOStopLoss], Convert(VarChar(250), [ISOCigna]) AS [ISOCigna], Convert(VarChar(250), [ISOThirdParty]) AS [ISOThirdParty], Convert(VarChar(250), [ISORetirees]) AS [ISORetirees], Convert(VarChar(250), [ASOReimbCigna]) AS [ASOReimbCigna], Convert(VarChar(250), [ASOReimbOther]) AS [ASOReimbOther]'



Declare @a table (pos int, rn int identity(1,1))
Declare @ct int = 0
Declare @pos int
Declare @oldpos int
Select @oldpos=0
select @pos=charindex(char(10),@var) 
while @ct <= (select len(@var) - len(replace(@var,char(10),'')))
    begin
    insert into @a Values (@pos)
    Select @oldpos=@pos
    select @pos=charindex(char(10),Substring(@var,@pos + 1,len(@var))) + @pos
    select @ct = @ct + 1
end

Select 
    --*,
    substring(@var,isnull(a2.pos,0),a1.pos) as SubSet
from @a a1
left join @a a2 on a2.rn  = a1.rn - 1


--edit for your comment...

select 
    --forces a CR at the comma before 950 characters 
    stuff(replace(@var,char(10),''),charindex('],',replace(@var,char(10),''),950),0,CHAR(13)+CHAR(10))

1 个答案:

答案 0 :(得分:3)

<xsd:attribute name="expire-groups-upon-timeout">
                <xsd:annotation>
                    <xsd:documentation>
                        Boolean flag specifying, if a group is completed due to timeout (reaper or
                        'group-timeout(-expression)'), whether the group should be removed.
                        When true, late arriving messages will form a new group. When false, they
                        will be discarded. Default is 'true' for an aggregator and 'false' for a
                        resequencer.
                    </xsd:documentation>
                </xsd:annotation>
                <xsd:simpleType>
                    <xsd:union memberTypes="xsd:boolean xsd:string" />
                </xsd:simpleType>

<强>返回

Declare @S varchar(max) = 'TransID, Convert(VarChar(250), [TPSYN]) AS [TPSYN], Convert(VarChar(250), [SureFitYN]) AS [SureFitYN], Convert(VarChar(250), [AccountNbr]) AS [AccountNbr], Convert(VarChar(250), [Account Name]) AS [Account Name], Convert(VarChar(250), [EffectiveDate]) AS [EffectiveDate], Convert(VarChar(250), [IM]) AS [IM], Convert(VarChar(250), [RevisionDate]) AS [RevisionDate], Convert(VarChar(250), [AccountAddress]) AS [AccountAddress], Convert(VarChar(250), [LSOCode]) AS [LSOCode], Convert(VarChar(250), [ASONonASOBoth]) AS [ASONonASOBoth], Convert(VarChar(250), [MedicalYN]) AS [MedicalYN], Convert(VarChar(250), [NonManagedCareYN]) AS [NonManagedCareYN], Convert(VarChar(250), [ManagedCareYN]) AS [ManagedCareYN], Convert(VarChar(250), [HRAYN]) AS [HRAYN], Convert(VarChar(250), [MedHRAYN]) AS [MedHRAYN], Convert(VarChar(250), [LPHRAYN]) AS [LPHRAYN], Convert(VarChar(250), [HealthyFutYN]) AS [HealthyFutYN], Convert(VarChar(250), [HAHRAYN]) AS [HAHRAYN], Convert(VarChar(250), [HSAYN]) AS [HSAYN], Convert(VarChar(250), [FSAHealthCare]) AS [FSAHealthCare], Convert(VarChar(250), [FSADependentCare]) AS [FSADependentCare], Convert(VarChar(250), [DentalYN]) AS [DentalYN], Convert(VarChar(250), [TaftHartley]) AS [TaftHartley], Convert(VarChar(250), [ParameterComments]) AS [ParameterComments], Convert(VarChar(250), [MLRAvgLivesNumber]) AS [MLRAvgLivesNumber], Convert(VarChar(250), [MLRAvgLivesRptYear]) AS [MLRAvgLivesRptYear], Convert(VarChar(250), [MLRContact]) AS [MLRContact], Convert(VarChar(250), [MLRContactAddress1]) AS [MLRContactAddress1], Convert(VarChar(250), [MLRContactAddress2]) AS [MLRContactAddress2], Convert(VarChar(250), [MLRContactCity]) AS [MLRContactCity], Convert(VarChar(250), [MLRContactState]) AS [MLRContactState], Convert(VarChar(250), [MLRContactZip]) AS [MLRContactZip], Convert(VarChar(250), [HealthRiskAssessment]) AS [HealthRiskAssessment], Convert(VarChar(250), [ErisaYN]) AS [ErisaYN], Convert(VarChar(250), [ErisaPlanName]) AS [ErisaPlanName], Convert(VarChar(250), [ErisaPlanNumber]) AS [ErisaPlanNumber], Convert(VarChar(250), [ErisaPlanEndsMM]) AS [ErisaPlanEndsMM], Convert(VarChar(250), [ErisaPlanEndsDD]) AS [ErisaPlanEndsDD], Convert(VarChar(250), [ErisaAdministrator]) AS [ErisaAdministrator], Convert(VarChar(250), [ErisaClaimAdministrator]) AS [ErisaClaimAdministrator], Convert(VarChar(250), [ErisaCost]) AS [ErisaCost], Convert(VarChar(250), [ErisaEOB]) AS [ErisaEOB], Convert(VarChar(250), [ErisaEOBName]) AS [ErisaEOBName], Convert(VarChar(250), [ErisaEOBAddress1]) AS [ErisaEOBAddress1], Convert(VarChar(250), [ErisaEOBAddress2]) AS [ErisaEOBAddress2], Convert(VarChar(250), [ErisaEOBCity]) AS [ErisaEOBCity], Convert(VarChar(250), [ErisaEOBState]) AS [ErisaEOBState], Convert(VarChar(250), [ErisaEOBZip]) AS [ErisaEOBZip], Convert(VarChar(250), [ErisaEOBPhone]) AS [ErisaEOBPhone], Convert(VarChar(250), [ErisaPAName]) AS [ErisaPAName], Convert(VarChar(250), [ErisaPAAddress1]) AS [ErisaPAAddress1], Convert(VarChar(250), [ErisaPAAddress2]) AS [ErisaPAAddress2], Convert(VarChar(250), [ErisaPACity]) AS [ErisaPACity], Convert(VarChar(250), [ErisaPAState]) AS [ErisaPAState], Convert(VarChar(250), [ErisaPAZip]) AS [ErisaPAZip], Convert(VarChar(250), [ErisaPAPhone]) AS [ErisaPAPhone], Convert(VarChar(250), [ErisaLAName]) AS [ErisaLAName], Convert(VarChar(250), [ErisaLAAddress1]) AS [ErisaLAAddress1], Convert(VarChar(250), [ErisaLAAddress2]) AS [ErisaLAAddress2], Convert(VarChar(250), [ErisaLACity]) AS [ErisaLACity], Convert(VarChar(250), [ErisaLAState]) AS [ErisaLAState], Convert(VarChar(250), [ErisaLAZip]) AS [ErisaLAZip], Convert(VarChar(250), [ErisaLAPhone]) AS [ErisaLAPhone], Convert(VarChar(250), [ERISAComments]) AS [ERISAComments], Convert(VarChar(250), [CSNApproval]) AS [CSNApproval], Convert(VarChar(250), [CSNPPO]) AS [CSNPPO], Convert(VarChar(250), [CSNOAP]) AS [CSNOAP], Convert(VarChar(250), [CSNSupplemental]) AS [CSNSupplemental], Convert(VarChar(250), [CSNReplacement]) AS [CSNReplacement], Convert(VarChar(250), [CSNType]) AS [CSNType], Convert(VarChar(250), [CSNNBNIL915]) AS [CSNNBNIL915], Convert(VarChar(250), [CSNNBNPA910]) AS [CSNNBNPA910], Convert(VarChar(250), [CSNNBNPA911]) AS [CSNNBNPA911], Convert(VarChar(250), [CSNNBNFL918]) AS [CSNNBNFL918], Convert(VarChar(250), [CSNNBNCA915]) AS [CSNNBNCA915], Convert(VarChar(250), [CSNNBNMA904]) AS [CSNNBNMA904], Convert(VarChar(250), [CSNOwnLogo]) AS [CSNOwnLogo], Convert(VarChar(250), [CSNNBNAllBranches]) AS [CSNNBNAllBranches], Convert(VarChar(250), [CSNNBNBranchComment]) AS [CSNNBNBranchComment], Convert(VarChar(250), [ASOStopLoss]) AS [ASOStopLoss], Convert(VarChar(250), [ASOCigna]) AS [ASOCigna], Convert(VarChar(250), [ASOThirdParty]) AS [ASOThirdParty], Convert(VarChar(250), [ASORetirees]) AS [ASORetirees], Convert(VarChar(250), [ISOStopLoss]) AS [ISOStopLoss], Convert(VarChar(250), [ISOCigna]) AS [ISOCigna], Convert(VarChar(250), [ISOThirdParty]) AS [ISOThirdParty], Convert(VarChar(250), [ISORetirees]) AS [ISORetirees], Convert(VarChar(250), [ASOReimbCigna]) AS [ASOReimbCigna], Convert(VarChar(250), [ASOReimbOther]) AS [ASOReimbOther]'

;with cte as (
                Select *,Grp = sum(len(RetVal)-0) over (Order By RetSeq) /  950
                 From  [dbo].[udf-Str-Parse-8K](replace(@S,'],','],|'),'|') 
)
Select S = replace(Stuff((Select '' +String + '|||'
    From (
            Select Grp
                  ,String = (Select Stuff((Select ' '+RetVal From cte Where Grp=A.Grp For XML Path ('')),1,1,'') )
             From  (Select Distinct Grp From cte) A
          ) A
    Order by Grp
    For XML Path ('')),1,0,'') 
    ,'|||',char(13))

解析UDF - 如果需要可以内联

TransID, Convert(VarChar(250), [TPSYN]) AS [TPSYN], Convert(VarChar(250), [SureFitYN]) AS [SureFitYN], Convert(VarChar(250), [AccountNbr]) AS [AccountNbr], Convert(VarChar(250), [Account Name]) AS [Account Name], Convert(VarChar(250), [EffectiveDate]) AS [EffectiveDate], Convert(VarChar(250), [IM]) AS [IM], Convert(VarChar(250), [RevisionDate]) AS [RevisionDate], Convert(VarChar(250), [AccountAddress]) AS [AccountAddress], Convert(VarChar(250), [LSOCode]) AS [LSOCode], Convert(VarChar(250), [ASONonASOBoth]) AS [ASONonASOBoth], Convert(VarChar(250), [MedicalYN]) AS [MedicalYN], Convert(VarChar(250), [NonManagedCareYN]) AS [NonManagedCareYN], Convert(VarChar(250), [ManagedCareYN]) AS [ManagedCareYN], Convert(VarChar(250), [HRAYN]) AS [HRAYN], Convert(VarChar(250), [MedHRAYN]) AS [MedHRAYN], Convert(VarChar(250), [LPHRAYN]) AS [LPHRAYN], Convert(VarChar(250), [HealthyFutYN]) AS [HealthyFutYN], Convert(VarChar(250), [HAHRAYN]) AS [HAHRAYN],
Convert(VarChar(250), [HSAYN]) AS [HSAYN], Convert(VarChar(250), [FSAHealthCare]) AS [FSAHealthCare], Convert(VarChar(250), [FSADependentCare]) AS [FSADependentCare], Convert(VarChar(250), [DentalYN]) AS [DentalYN], Convert(VarChar(250), [TaftHartley]) AS [TaftHartley], Convert(VarChar(250), [ParameterComments]) AS [ParameterComments], Convert(VarChar(250), [MLRAvgLivesNumber]) AS [MLRAvgLivesNumber], Convert(VarChar(250), [MLRAvgLivesRptYear]) AS [MLRAvgLivesRptYear], Convert(VarChar(250), [MLRContact]) AS [MLRContact], Convert(VarChar(250), [MLRContactAddress1]) AS [MLRContactAddress1], Convert(VarChar(250), [MLRContactAddress2]) AS [MLRContactAddress2], Convert(VarChar(250), [MLRContactCity]) AS [MLRContactCity], Convert(VarChar(250), [MLRContactState]) AS [MLRContactState], Convert(VarChar(250), [MLRContactZip]) AS [MLRContactZip], Convert(VarChar(250), [HealthRiskAssessment]) AS [HealthRiskAssessment], Convert(VarChar(250), [ErisaYN]) AS [ErisaYN],
Convert(VarChar(250), [ErisaPlanName]) AS [ErisaPlanName], Convert(VarChar(250), [ErisaPlanNumber]) AS [ErisaPlanNumber], Convert(VarChar(250), [ErisaPlanEndsMM]) AS [ErisaPlanEndsMM], Convert(VarChar(250), [ErisaPlanEndsDD]) AS [ErisaPlanEndsDD], Convert(VarChar(250), [ErisaAdministrator]) AS [ErisaAdministrator], Convert(VarChar(250), [ErisaClaimAdministrator]) AS [ErisaClaimAdministrator], Convert(VarChar(250), [ErisaCost]) AS [ErisaCost], Convert(VarChar(250), [ErisaEOB]) AS [ErisaEOB], Convert(VarChar(250), [ErisaEOBName]) AS [ErisaEOBName], Convert(VarChar(250), [ErisaEOBAddress1]) AS [ErisaEOBAddress1], Convert(VarChar(250), [ErisaEOBAddress2]) AS [ErisaEOBAddress2], Convert(VarChar(250), [ErisaEOBCity]) AS [ErisaEOBCity], Convert(VarChar(250), [ErisaEOBState]) AS [ErisaEOBState], Convert(VarChar(250), [ErisaEOBZip]) AS [ErisaEOBZip], Convert(VarChar(250), [ErisaEOBPhone]) AS [ErisaEOBPhone], Convert(VarChar(250), [ErisaPAName]) AS [ErisaPAName],
Convert(VarChar(250), [ErisaPAAddress1]) AS [ErisaPAAddress1], Convert(VarChar(250), [ErisaPAAddress2]) AS [ErisaPAAddress2], Convert(VarChar(250), [ErisaPACity]) AS [ErisaPACity], Convert(VarChar(250), [ErisaPAState]) AS [ErisaPAState], Convert(VarChar(250), [ErisaPAZip]) AS [ErisaPAZip], Convert(VarChar(250), [ErisaPAPhone]) AS [ErisaPAPhone], Convert(VarChar(250), [ErisaLAName]) AS [ErisaLAName], Convert(VarChar(250), [ErisaLAAddress1]) AS [ErisaLAAddress1], Convert(VarChar(250), [ErisaLAAddress2]) AS [ErisaLAAddress2], Convert(VarChar(250), [ErisaLACity]) AS [ErisaLACity], Convert(VarChar(250), [ErisaLAState]) AS [ErisaLAState], Convert(VarChar(250), [ErisaLAZip]) AS [ErisaLAZip], Convert(VarChar(250), [ErisaLAPhone]) AS [ErisaLAPhone], Convert(VarChar(250), [ERISAComments]) AS [ERISAComments], Convert(VarChar(250), [CSNApproval]) AS [CSNApproval], Convert(VarChar(250), [CSNPPO]) AS [CSNPPO], Convert(VarChar(250), [CSNOAP]) AS [CSNOAP],
Convert(VarChar(250), [CSNSupplemental]) AS [CSNSupplemental], Convert(VarChar(250), [CSNReplacement]) AS [CSNReplacement], Convert(VarChar(250), [CSNType]) AS [CSNType], Convert(VarChar(250), [CSNNBNIL915]) AS [CSNNBNIL915], Convert(VarChar(250), [CSNNBNPA910]) AS [CSNNBNPA910], Convert(VarChar(250), [CSNNBNPA911]) AS [CSNNBNPA911], Convert(VarChar(250), [CSNNBNFL918]) AS [CSNNBNFL918], Convert(VarChar(250), [CSNNBNCA915]) AS [CSNNBNCA915], Convert(VarChar(250), [CSNNBNMA904]) AS [CSNNBNMA904], Convert(VarChar(250), [CSNOwnLogo]) AS [CSNOwnLogo], Convert(VarChar(250), [CSNNBNAllBranches]) AS [CSNNBNAllBranches], Convert(VarChar(250), [CSNNBNBranchComment]) AS [CSNNBNBranchComment], Convert(VarChar(250), [ASOStopLoss]) AS [ASOStopLoss], Convert(VarChar(250), [ASOCigna]) AS [ASOCigna], Convert(VarChar(250), [ASOThirdParty]) AS [ASOThirdParty], Convert(VarChar(250), [ASORetirees]) AS [ASORetirees], Convert(VarChar(250), [ISOStopLoss]) AS [ISOStopLoss],
Convert(VarChar(250), [ISOCigna]) AS [ISOCigna], Convert(VarChar(250), [ISOThirdParty]) AS [ISOThirdParty], Convert(VarChar(250), [ISORetirees]) AS [ISORetirees], Convert(VarChar(250), [ASOReimbCigna]) AS [ASOReimbCigna], Convert(VarChar(250), [ASOReimbOther]) AS [ASOReimbOther]
  

编辑 - INLINE Verserion(不需要UDF)

CREATE FUNCTION [dbo].[udf-Str-Parse-8K] (@String varchar(max),@Delimiter varchar(25))
Returns Table 
As
Return (  
    with   cte1(N)   As (Select 1 From (Values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) N(N)),
           cte2(N)   As (Select Top (IsNull(DataLength(@String),0)) Row_Number() over (Order By (Select NULL)) From (Select N=1 From cte1 a,cte1 b,cte1 c,cte1 d) A ),
           cte3(N)   As (Select 1 Union All Select t.N+DataLength(@Delimiter) From cte2 t Where Substring(@String,t.N,DataLength(@Delimiter)) = @Delimiter),
           cte4(N,L) As (Select S.N,IsNull(NullIf(CharIndex(@Delimiter,@String,s.N),0)-S.N,8000) From cte3 S)

    Select RetSeq = Row_Number() over (Order By A.N)
          ,RetVal = LTrim(RTrim(Substring(@String, A.N, A.L)))
    From   cte4 A
);
--Orginal Source http://www.sqlservercentral.com/articles/Tally+Table/72993/
--Select * from [dbo].[udf-Str-Parse-8K]('Dog,Cat,House,Car',',')
--Select * from [dbo].[udf-Str-Parse-8K]('John||Cappelletti||was||here','||')