Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My store procedure as follows
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[Shortcode_Accommodation] (@Keyword varchar(50))
as

declare @Hotel varchar(25),
@Phone varchar(25),
@final varchar(max)

create table #TempTable(res varchar(max)) 
begin
insert into #Temptable(res) values('Dear Students, Hotel Accommodation is');
insert into #Temptable(res)
select CONVERT(varchar, ROW_NUMBER() over(order by Hotel_Name))+'. '+Hotel_Name+','+Phoneno+''
from Tb_Accommodation where Active <> 'D' and Description = @Keyword
insert into #Temptable(res) values('By marine');

select * from #Temptable 
end

when I execute the above store procedure output as follows
SQL
exec [Shortcode_Accommodation] 'Accommodation'

Dear Students, Hotel Accommodation is<br />
1. HOTEL RAAJ BHAAVAN,26404621/22<br />
2. HOTEL SHRI VALLI RESIDENCyY,26422297/42668009<br />
By marine


But i want the output to be needed in single line as follows

Dear Students,HotelAccommodation is 1.HOTEL RAAJ BHAAVAN,26404621/22 2.HOTEL SHRI VALLI RESIDENCY,26422297/42668009 By marine
Posted
Updated 1-Mar-14 21:19pm
v2
Comments
Krunal Rohit 2-Mar-14 3:21am    
have you tried out something ?

-KR

1 solution

alter proc [dbo].[Shortcode_Accommodation] (@Keyword varchar(50))
as
 
declare @Hotel varchar(25),
@Phone varchar(25),
@final varchar(max)
 
create table #TempTable(res varchar(max)) 
begin
Declare @AddHotelNames nvarchar(max)



select @AddHotelNames=COALESCE(@AddHotelNames+',','')+ ' '+CONVERT(varchar, ROW_NUMBER() over(order by Hotel_Name))+'. '+Hotel_Name+','+Phoneno+''
from Tb_Accommodation  where  Active <> 'D' Description = @Keyword

print  @AddHotelNames
set @AddHotelNames='Dear Students, Hotel Accommodation is'+@AddHotelNames+'By marine'

insert into #Temptable(res) values(@AddHotelNames);
 
select * from #Temptable 
end
 
Share this answer
 
Comments
[no name] 3-Mar-14 0:47am    
Thanks,
it is working fine.

Rgds,
Narasiman P.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900