Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello friends,
Below is my store procedure
create procedure [dbo].[temptable] (@branchid int,@academicyearid int)
as 
begin
set nocount on
begin try
begin tran
declare @branchname varchar(50)
declare @acfy int ;
declare @acty int
select @branchname=Branch_name from Branch where Branch_id=@branchid
select @acfy=Acadamic_year_from,@acty=Acadamic_year_to from Acadamic_year where Acadamic_year_id=@academicyearid
create table #temptable(Brach_name int,Acadamic_year_from smallint,Acadamic_year_to smallint)
insert into #temptable(Brach_name,Acadamic_year_from,Acadamic_year_to)values(@branchname,@acfy,@acty)
select * from #temptable;
commit
end try
begin catch
rollback
end catch
end
exec temptable 141,11

e
my task is i want to bind branchname and fromyear and to year to my window application form. is the procedure right or not? When execution there is no error on this store procedure but when i trace this in dubug mode everything ok.but it doesnt execute line select * from # temptable.i want to return thse three column to my windows form. please help me
Posted

Dont use transaction for inserting values into temp table.

SQL
create procedure [dbo].[temptable] (@branchid int,@academicyearid int)
as 
begin
set nocount on

declare @branchname varchar(50)
declare @acfy int ;
declare @acty int
select @branchname=Branch_name from Branch where Branch_id=@branchid
select @acfy=Acadamic_year_from,@acty=Acadamic_year_to from Acadamic_year where Acadamic_year_id=@academicyearid
create table #temptable(Brach_name int,Acadamic_year_from smallint,Acadamic_year_to smallint)
insert into #temptable(Brach_name,Acadamic_year_from,Acadamic_year_to)values(@branchname,@acfy,@acty)
select * from #temptable;

end

exec temptable 141,11
 
Share this answer
 
SQL
create procedure temptable (@branchId INT,@academicYearId INT)
as 
begin
set nocount on
declare @branchname VARCHAR(50)
declare @acfy INT;
declare @acty INT
select @branchname=Branch_name from Branch where Branch_id=@branchid
select @acfy=Acadamic_year_from,@acty=Acadamic_year_to from Acadamic_year where Acadamic_year_id=@academicyearid
create table #temptable(Brach_name int,Acadamic_year_from smallint,Acadamic_year_to smallint)
insert into #temptable(Brach_name,Acadamic_year_from,Acadamic_year_to)values(@branchname,@acfy,@acty)
select * from #temptable;
end
 
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