SQL Server- Bulk Export Data without html formatting and line spaces -


i need export database data text file. query looks this:

select category1, category2, category3  dbo.tbl1 category1 = 'jp-4' , category2> 4; 

this works fine data, there html formatting in table entries such <p>,</p>,<br>,</br> etc. ideally need remove when exporting data text file. i've tried simple replace query didn't work. i've got issue line splits , need remove (\n\r). suggestions on how appreciated!

the data format this:

category1: jp-4 category2: 4 category3:<p>neque porro quisquam est qui dolorem ipsum quia dolor</p>  <p>amet, consectetur, adipisci velit</p> category4:<p>neque porro quisquam est qui dolorem ipsum quia dolor</p>   

i got work with:

select replace(replace("category3",'<p>',''),'</p>','')  dbo.tbl1 category1= 'jp-4' , category2> 4; 

but issue i've got 15 columns in total , need several different tags each column , thought there must better/more efficient way of doing it. i've looked on internet couldn't find solution.

i created function strip out non alpha-numeric characters situations similar this. full code is:

create function dbo.ufngenstripnonalphanumchars (     @inputstring nvarchar(max) )  returns nvarchar(max) begin  declare @keepchars nvarchar(50) = '%[^a-z0-9 ]%' --a-z, 0-9, space  while patindex(@keepchars, @inputstring) > 0     begin        set @inputstring = stuff(@inputstring, patindex(@keepchars, @inputstring), 1, '');     end   return @inputstring;  end; 

the key in use patindex function for. set @keepchars = '%[^a-z0-9 ]%', means finds not (the carrot - ^) either alphabetic or numeric character. should able tweak criteria pass patindex results want (note patindex not regular expressions).

hopefully points in helpful direction.

edit:

after further review, here approach more closely targets html code (see best way strip html tags string in sql server?):

declare @start int declare @end int declare @length int set @start = charindex('<',@inputstring) set @end = charindex('>',@inputstring,charindex('<',@inputstring)) set @length = (@end - @start) + 1 while @start > 0 , @end > 0 , @length > 0 begin     set @inputstring = stuff(@inputstring,@start,@length,'')     set @start = charindex('<',@inputstring)     set @end = charindex('>',@inputstring,charindex('<',@inputstring))     set @length = (@end - @start) + 1 end  return @inputstring; 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -