Quantcast
Channel: Database Design forum
Viewing all articles
Browse latest Browse all 2729

concatenate rows by new line separator from sp_helptext value

$
0
0

I have a query like this below

DEclare @SQL VARCHAR(MAX)
Declare @FinalSQL VARCHAR(MAX)
Declare @val Varchar(MAX); 
DECLARE @SchemaName nvarchar(50)= 'aksfood'
CREATE TABLE #T1 (text varchar(max))
CREATE TABLE #T2 (text varchar(max))

SET @SQL = ( select 'sp_helptext '+ '[' + @SchemaName + '.' + name + ']'  from sys.procedures Where Schema_id = 5 and Name ='Add_Edit_UserType')

INSERT into #T1  execute('execute ' + @SQL )
--SET @FinalSQL = 

INSERT into #T2
Select Replace(text,'aksfood','souravtest')  from #T1

--Select * from #t2 WHERE text LIKE '%[a-zA-Z][a-zA-Z]%'


Select @val = COALESCE(@val + CHAR(13) + text, text) 
        From #T2 where text LIKE '%[a-zA-Z][a-zA-Z]%'
Select @val;

Drop table #T1
Drop table #T2

My query return result in one line sepated by comma like below

CREATE procedure [souravtest].[Add_Edit_UserType]    @company_id INT = NULL,    @Sorting Varchar(100) =NULL,    @h_user_id INT = NULL,    @is_success VARCHAR(500) OUT   AS   BEGIN    BEGIN try      select utm.user_type_id,sdm.department ,utm.company_id,utm.user_type_name, utm.hierarchical_order        INTO #tmpReport      from [dbo].[sfa_user_type_master] utm left join sfa_department_master sdm on sdm.id=utm.department_id      where utm.isactive = 1 and utm.company_id=@company_id     if(@sorting is null)         Begin            SELECT * from #tmpReport        SET @is_success = 'true';         end         else         begin          DECLARE @SQLStatement1 varchar(MAX)               SELECT @SQLStatement1 = 'Select * from #tmpReport ORDER BY ' + @sorting                EXEC(@SQLStatement1)          SET @is_success = 'true';         drop table #tmpReport         end     --print 'test complete'    END try    BEGIN catch     SET @is_success = ERROR_MESSAGE();    END catch;   END;  

But I need a new line for each row instead of comma.

Thanks in advance.



Viewing all articles
Browse latest Browse all 2729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>