Click here to Skip to main content
15,916,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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),
@Room varchar(25),
@final varchar(max)
 
create table #TempTable(res varchar(max))  

begin
insert into #Temptable 
select ('Dear Students, Hotel Accommodation is ' + Hotel_Name + ',' +
Phoneno + ',' + Room_Rate +  ' By HIMT') as res from Tb_Hotel_Accommodation where Active <> 'D' and Description = @Keyword

select * from #Temptable 
end


when i execute the store procedure output as follows
SQL
exec [Shortcode_Accommodation]  'ACCOMMODATION'


Dear Students, Hotel Accommodation is SATKAR LODGE,9380197278/26425881/33570477,Single Non-AC 425,Double Non-AC 525,Double AC 1145 By HIMT

Dear Students, Hotel Accommodation is HOTEL RAAJ BHAAVAN,26404621/22,Single Non-AC 900,Double Non-AC 1200,Single AC 1100,Double AC 1200 By HIMT



But i want when i execute the store procedure output i want as follows

Dear Students, Hotel Accommodation is 1.SATKAR LODGE,9380197278/26425881/33570477,Single Non-AC 425,Double Non-AC 525,Double AC 1145,2.RAAJ BHAAVAN,26404621/22,Single Non-AC 900,Double Non-AC 1200,Single AC 1100,Double AC 1200 By HIMT

from my above store procedure what mistake i made.

regards,
narasiman P.
Posted
Updated 28-Feb-14 22:00pm
v3

1 solution

What you do is that you insert beginning and ending parts to every line. therefore they show up for each line. you should insert them into #Temptable only once.

SQL
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+','+Room_Rate
from #Tb_Hotel_Accommodation
insert into #Temptable(res) values('by Ozan');

select * from #Temptable


you can use ROW_NUMBER() function as here: http://technet.microsoft.com/en-us/library/ms186734.aspx[^]
 
Share this answer
 

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