Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have two tables named detail
SQL
table and employee.detail table in which values are detailid,desigid,allowancename,createddate,createdby,updateddate,updatedby etc
 and
 employee table contains desigid,desigcode,designame etc.
I need to pass detail table values to a single parameter and at the same time i want to pass values to both these tables (using table valued parameters).Can you help me for completing my doubt please.
Posted
Updated 5-Dec-12 19:24pm
v3
Comments
Patel Shailendra 6-Dec-12 1:04am    
you want to create procedure to insert values in both the table.
renjimaramanan mr 6-Dec-12 1:10am    
ya
Patel Shailendra 6-Dec-12 1:22am    
i think you have to create designation table first and this table is inserted by admin and employee.details is other procedure for fast insertion and it is inserted by employee. its better to create two different procedure then creating single procedure.
renjimaramanan mr 6-Dec-12 1:35am    
thanks...

Hi again,

I guess I understood your requirement.
You want to pass a table variable in stored procedure as a parameter... :)
Well first you will need to define the structure of the table.
ex:
SQL
create table A(
AId int primary key,
AName varchar(20))

Then create a Table type and declare its structure too.
SQL
create type AType as Table(
AId int,AName varchar(20));

Thn create a Stored Procedure having table type as parameter:
SQL
create procedure Test
 @x AType
 as
 insert into A(AId,AName)
 select * from @x;
go

Next step would be to declare a table type variable and refer it to the tabletype wch we have created:
SQL
declare @y as AType;

Then insert some values in the above parameter..which shud be the actual data wat u wana enter..
Then pass this parameter to the stored proc n execute the stored proc.
SQL
insert into @y(AId,AName)
 values(1,'Adidas')
 (2,'Nike');

SQL
exec Test @y ;


Here you go...you are done...Happy Coding... :)
 
Share this answer
 
Comments
renjimaramanan mr 6-Dec-12 1:50am    
thank u so much anurag.. :)
Anurag Sinha V 6-Dec-12 1:55am    
np...
and dnt forget to give 5 stars to the solution...:P:P

cheers
renjimaramanan mr 6-Dec-12 2:39am    
kk... :)
Hi,

The question which you have asked is unclear.
Can u rephrase it correctly,i.e what exactly you wana do?
 
Share this answer
 
Comments
renjimaramanan mr 6-Dec-12 1:13am    
i want pass values of a table to a parameter

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