Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to write stored procedure for get parameter values from tabel1
and after insert parameter values toameter values to table2 in single stored procedure?
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
--use webtemplate
ALTER procedure  [dbo].[ei_sp_LocationInsert] 
(
@Name varchar(100)=null,
@Code varchar(35)=null,
@Desc varchar(255)=null,
@CityID int=null,
@StateID int=null,
@CountryID int=null,
@Company int=null



)
as begin


select stateID,cityID,countryID from tabe1 where ID=@company
(
@stateID=stateID
@cityID=cityID
@countryID=countryID
)
insert into table2
(
[Name],
Code,
[Desc],
CityID,
StateID,
CountryID,
company

)
values
(
@Name,
@Code,
@Desc,
@CityID,
@StateID,
@CountryID,
@Company,

)




end
Posted

change like this and try

SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
--use webtemplate
ALTER procedure  [dbo].[ei_sp_LocationInsert] 
(
@Name varchar(100)=null,
@Code varchar(35)=null,
@Desc varchar(255)=null,
@CityID int=null,
@StateID int=null,
@CountryID int=null,
@Company int=null
 

 
)
as 
begin
 


select  @stateID=stateID from tabe1 where ID=@company
select   @cityID=cityID  from tabe1 where ID=@company
select  @countryID=countryID from tabe1 where ID=@company
 
insert into table2
(
[Name],
Code,
[Desc],
CityID,
StateID,
CountryID,
company
 
)
values
(
@Name,
@Code,
@Desc,
@CityID,
@StateID,
@CountryID,
@Company,
 
)
 

 

end
 
Share this answer
 
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
--use webtemplate
ALTER procedure [dbo].[ei_sp_LocationInsert]
(
@Name varchar(100)=null,
@Code varchar(35)=null,
@Desc varchar(255)=null,
@CityID int=null,
@StateID int=null,
@CountryID int=null,
@Company int=null
)
as
begin
select @stateID=stateID ,@cityID=cityID, @countryID=countryID from tabe1 where ID=@company

insert into table2
(
[Name],
Code,
[Desc],
CityID,
StateID,
CountryID,
company

)
values
(
@Name,
@Code,
@Desc,
@CityID,
@StateID,
@CountryID,
@Company,

)
end
 
Share this answer
 
Comments
Vasim889 28-Jan-12 3:01am    
it's working .thanks

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