Author |
Topic |
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 05:58:28
|
create table table1 (phone int,kod_name_d int ) -- create table table2 (nam_d nvarchar(30),kod int) insert into table2 values('james',1)insert into table2 values('stivens',2)insert into table2 values('carlos',3)how i make created procedure for insert to table1 when name=james then in kod_name_d insert 1 (kod table2)for example i inserted table 1 (11111,'james')after inserted table1phone kod_name_d----- ----- 11111 1kmkmmm |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-05 : 06:03:36
|
you mean this i guesscreate procedure inserttable1@phone int,@name varchar(30)asinsert table1select @phone,kodfrom table2where nam_d = @namego and if you're not sure if table2 will have record with passed name you can even add that insert logoc also inside thisthe procedure can be called as belowEXEC inserttable1 @phone=11111,@name='james' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 06:14:02
|
thank you very muchkmkmmm |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 06:34:32
|
but i once again question create table table3(phone int,k_name int,fname nvarchar(20))when i inserted table1 with procedure inserttable1when inserted phone to table1 then insert this data to table as trigger but my server is mssql2000 in my server have not trigger for exampleinsert into table 1 EXEC inserttable1 @phone='',@name='james'table1phone name-- --- 0 1EXEC inserttable1 @phone='33333',@name='james'table1phone name-- --- 0 1table3phone k_name f_name33333 1 kmkmmm |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 07:08:21
|
??????????????kmkmmm |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-05 : 07:12:48
|
quote: Originally posted by pascal_jimi but i once again question create table table3(phone int,k_name int,fname nvarchar(20))when i inserted table1 with procedure inserttable1when inserted phone to table1 then insert this data to table as trigger but my server is mssql2000 in my server have not trigger for exampleinsert into table 1 EXEC inserttable1 @phone='',@name='james'table1phone name-- --- 0 1EXEC inserttable1 @phone='33333',@name='james'table1phone name-- --- 0 1table3phone k_name f_name33333 1 kmkmmm
trigger?I never suggested any trigger usage.when you use below execute statementEXEC inserttable1 @phone='',@name='james'you'll get 0 as value for phone as phone field is of type int and gets default value of 0i dont know how you got posted result forEXEC inserttable1 @phone='33333',@name='james'as per my suggestion you should be getting thisphone kod_name_d----- -----33333 1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 07:34:25
|
thank you visakhi posted result for your suggestion but in database have many tables for selection for example table 1phone kod1 kod2 adress kod3 email kod4 kod5--- --- --- --- --- ------- ---- --- ---- ----table2name1 kod1---- ----christie 1james 2table3name2 kod2------- -------jhony 1paul 2table3 name2 kod2----- -------hasan 1rashid 2 table4 name4 kod4------ ---asif 1natiq 2table5 name5 kod5---------- -------arnold 1vandame 1insert table111111 ,james ,jhony,chicago,hasan,www.mail.ru , asif,arnoldafter inserted table 1phone kod1 kod2 adress kod3 email kod4 kod5--- --- --- --- --- ------- ---- --- 11111 2 1 chicago 1 www.mail.ru 1 1kmkmmm |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 07:35:10
|
how make i create procedure for 5 tableskmkmmm |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-05 : 08:24:20
|
???????????????????kmkmmm |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-07 : 10:06:42
|
quote: Originally posted by pascal_jimi how make i create procedure for 5 tableskmkmmm
Same as how i gave suggestion for 2 tables. just extend it to include the logic for all the 5 tables.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-07-07 : 16:22:49
|
thank you very much visakhkmkmmm |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-08 : 01:27:43
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|