Get delimited data from table in SQL Server -


i have table named tbl_subacc , fields are: account, branch, ftype, armcode,drlsttrdate, crlsttrdate, telno etc.

currently getting | separated data using following query:

select account +'|'+ branch +'|' + armcode delimited_data    reportingframework.dbo.tbl_subacc 

this gives result as:

    delimited_data     111123|01|c0013     111124|01|c0013     1234121|05|c0324     0120219|02|c0329     0212108|03|c3232     111121|01|c0013 

this want. but, above query requires fileds name given manually. want delimited data of fields without giving column names.

how can select * delimited data table?

declare @nsql nvarchar(max); set @nsql = ' select ' + stuff((     select '+''|''+isnull(cast(' + quotename(name) + ' nvarchar(max)),'''') '     sys.columns     object_id=object_id('your_table_name')     order column_id     xml path(''), type).value('/','nvarchar(max)'), 1, 5, '') + ' delimited_data your_table_name'; --print @nsql; exec (@nsql); 

replace your_table_name (twice) target table. properly, need cater conversion varchar , nulls. works poorly datetimes, come out in terrible format pipe-delimited consumption software. better if stop @ print @nsql , hand-tweak before running.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -