sql - How to select a specific line in a row with carriage returns -
using sql server 2012 i'm running following basic query
select macroid ,macrotext ,auditeventid ,audittypecode ,audittimestamp apxfirm.dbo.advmacro
however it's come attention every result row has numerous carriage returns embeded, , need specific row within rows.
below how result set looks in sql.
however when pasting in notepad it'll this.
[version] 3.5.1.212 [description] taxlot information populating holdings table [portfolios] @master [mode] management [autoprint] no [graph] no [sheet] no [attended] no [apply copies] no [page number by] report [number 1 page reports] no [consolidate composites] both [frames] yes [output file] txlotext [error file] txlotext [report] txlotext.rep report txlotext.rep $prifile 123103 $_outfile txlotext.xml gauge 2 1 prop mb frame g1 2 c y y y "report txlotext.rep" y - y y 0 0 100 100 000000 ffffff 0 1 "" ffffff 000000 360 0 0 6a240a n frame g0 2 r n n y "report txlotext.rep" y - y y 0 0 100 100 000000 ffffff 0 1 "" ffffff 000000 360 0 0 6a240a n
what need lines begin [report] including brackets, need information follows.
txlotext.rep report txlotext.rep
i'm not sure how query row within row.
select macroid ,macrotext ,auditeventid ,audittypecode ,audittimestamp ,ltrim(rtrim(left( right(macrotext,len(macrotext) - charindex('[report] ',macrotext) - len('[report] ')), charindex(char(13),right(macrotext,len(macrotext) - charindex('[report] ',macrotext) - len('[report] '))) - 1 ))) desiredline apxfirm.dbo.advmacro
use combination of charindex(), right(), left(), and/or substring() find want , cut string. char(13) carriage return.
Comments
Post a Comment