Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
in table record as follows

sno Descirption Hotelname Phoneno Roomrate Active
1 Accom1 Satarlodge 24745734/9840175805 SingleNonAC 500,Double AC 1000 A
2 Accom1 Sarvanalodge 24151212/9790578502 SingleNonAC 600 Double AC 1200 A
3 Accom2 Suryalodge 24851524/9852012312 SingleNonAC 1000 DoubleAC 1600 A
4 Accom2 kalpanlodge 24221222/9844121252 AC 1200 A

when i execute in using query output is getting correctly but when i uses that query in store procedure is not getting correctly

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER proc [dbo].[Shortcode_Accom] (@Keyword varchar(10))
as

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

select @Hotel=Hotelname,@Phone=Phoneno,@Room =Roomrate from Tb_Accommodation where Active <> 'D' and description = @Keyword

if(@Hotel!='')
begin
Set @final = 'Dear Students HIMT Hotel Accommodation is ' +@Hotel+',' +@Phone+ ','+@Room+ ' by marine'
select @final
end

When i execute the above store procedure output as follows

exec [Shortcode_Accom] 'Accom2'

Dear Students HIMT Hotel Accommodation is kalpanlodge,24221222/9844121252,AC 1200 by marine


i am executing the select query as follows

select Hotelname,Phoneno,Roomrate from Tb_Accommodation where Active <> 'D'and description = 'Accom2'

when i execute the above query output as follows
Suryalodge 24851524/9852012312 SingleNonAC 1000 DoubleAC 1600
kalpanlodge 24221222/9844121252 AC 1200

but when i execute using Store procedure

exec [Shortcode_Accom] 'Accom2'

Dear Students HIMT Hotel Accommodation is kalpanlodge,24221222/9844121252,AC 1200 by marine

please help me what is the mistake i made?

regards,
narasiman P.
Posted

1 solution

Try changing your SP to something like:

select 'Dear Students HIMT Hotel Accommodation is' +  Hotelname,Phoneno,Roomrate + ' by marine' from Tb_Accommodation 
where Active!='D' and description = @Keyword

You want multiple return values but your SP first part, with @val only contains one set of values and you only get one return set.

In the above, put in whatever intervening strings you wish between the return values.
 
Share this answer
 
v2

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