SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pascal_jimi
Posting Yak Master

Azerbaijan
150 Posts

Posted - 07/06/2013 :  05:24:43  Show Profile  Visit pascal_jimi's Homepage  Reply with Quote
create table table1
(phone int,kod_name int ,kod_fname int,kod_country int,kod_auto int) --

create table table2 (name_ nvarchar(30),kod int)
insert into table2 values('james',1)
insert into table2 values('stivens',2)
insert into table2 values('carlos',3)



create table table3 (f_name nvarchar(30),kod int)
insert into table2 values('john',1)
insert into table2 values('tayson',2)
insert into table2 values('swarzneger',3)




create table table4 (country nvarchar(30),kod int)
insert into table2 values('argentina',1)
insert into table2 values('brazilia',2)
insert into table2 values('korea',3)


create table table5 (m_auto nvarchar(30),kod int)
insert into table2 values('mersedec',1)
insert into table2 values('jaguar',2)
insert into table2 values('landrover',3)


how i make created procedure

for insert to table1

when name=james then in kod_name_d insert 1 (kod table2)
when fname=jhon then in kod_fname insert 1 (kod table3 )
when country=korea then in kod_country insert 3 (kod table4 )
when auto=jaguar then in kod_auto insert 2 (kod table5 )

forexamle

i inserted table 1

(11111,'james','jhon','korea','jaguar')

after inserted table1

table1
-----------
phone kod_name kod_fname kod_country kod_auto
----- -------- --------- ----------- --------
11111 1 1 3 2

kmkmmm

pascal_jimi
Posting Yak Master

Azerbaijan
150 Posts

Posted - 07/06/2013 :  07:11:32  Show Profile  Visit pascal_jimi's Homepage  Reply with Quote

i created procedure

but this procedure inserted only phone



create procedure inserttable1
@phone int,
@n nvarchar(30),@f nvarchar(30),@c nvarchar (30),@t nvarchar(30)
as
insert table1 select @phone,(select kod from table2 where name_='@n'),(select kod from table3 where f_name='@f'),
(select kod from table4 where country='c'),(select kod from table5 where m_auto='@t')

exec inserttable1 1111,'stivens','tayson','argentina','mersedec'

select*from table1

kmkmmm
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17642 Posts

Posted - 07/06/2013 :  09:59:28  Show Profile  Reply with Quote
remove the single quote around your variable

insert table1 
select @phone,
       (select kod from table2 where name_=@n),
       (select kod from table3 where f_name=@f),
       (select kod from table4 where country=@c), 
       (select kod from table5 where m_auto=@t) 



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000