Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My store procedure as follows
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER proc [dbo].[Shortcode_Accom]
as

 declare @Hotelname varchar(25),
 @Phoneno varchar(25),
 @Roomrate varchar(25),
 @CHK int,
 @MSG varchar(max),
 @final varchar(max),
 @Accommodation varchar(20)
  
 create table #TempTable(Hotelname varchar(25),Phoneno varchar(25),Roomrate varchar(25)) 
 begin tran
 
 IF @CHK=0
 begin
 SET @MSG= 'Invalid keyword'
 end
  
 select Hotelname,Phoneno,Roomrate from Tb_Accommodation where Active <> 'D'
 
 if @MSG = ''
 begin
      if @Accommodation= ''
     set @final = 'Dear Student, Thanks for contacting us. Please Check us'
     else
     Set @final = 'Dear Student, '  + @Hotelname+ +@Phoneno+ +@Roomrate+ 'By Marine'
 end
 
         else
     begin
       set @final = 'Invalid Keyword. Sorry try again with valid keyword or visit www.marineinstitute.com.SMS marine  xxx to 56100. Eg marine Accommodation1 to 56100'
     end

commit tran 


When i execute the above store procedure output as follows

SQL
exec [Shortcode_Accom]


Ouput as follows;

1 Satarlodge 24745734/9840175805 SingleNonAC 500,Double AC 1000 A
2 Sarvanalodge 24151212/9790578502 SingleNonAC 600 Double AC 1200 A

i want the above output in sentence format as follows

Dear Student, 1.Satarlodge,24745734/9840175805,SingleNonAC 500,Double AC 1000 2.Sarvanalodge 24151212/97905785600,Double AC 1200 By Marine


for getting a above output in sentence format what change i have to be made in my above store procedure to get the output in sentence format.

please help me.

regards,
narasiman P
Posted
Updated 6-Mar-14 17:50pm
v2

1 solution

The Data you see there seems to be the result of the query executed in the middle of your sp.
SQL
select Hotelname,Phoneno,Roomrate from Tb_Accommodation where Active <> 'D'

You should comment or delete this line.
and just before the
SQL
commit tran

add
SQL
select @final


But this won't show result because your variables are never used after declare.
But maybe what you wanted to was
SQL
select @Hotelname= Hotelname,@Phoneno= Phoneno,@Roomrate= Roomrate from Tb_Accommodation where Active <> 'D'


But, if I understand the result correctly, it looks like the query returns 2 rows, then you won't be able to assign these values into 1 variable.

Actually, none of your variable are assigned a value, you're checking:
<pre lang="SQL">if @Accommodation= ''
, but you only declared it before, this condition will always be true..

You should review your process first, because there is no logic in what you sent.
 
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