I came across the situation where I have to return a query from sp and
assign that to session.This sample query.Original one is large one having inner join on many table.Table name is dynamic.There 2 query in the sp.One should execute and other can send to the C# page.How to access that query in C#.I don’t want it’s result.just query.I have shown only one query here that I want to return.
example :
create Procedure Sample
(
@id int
)
as
begin
declare @pid varchar(10)
declare @query varchar(500)
set @pid = cast(@id as varchar(10))
set @query ='select * from Table1 where id = '+@pid+''
--Execute sp_executesql @query
--print @query
select @query
end
After Setting @Query Use SELECT. This will return to c sharp page.
Make sure not to use
ExecuteNonQuery()methodIn c sharp, for example