Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Very Urgent *****

Author  Topic 

BuddyRam
Starting Member

17 Posts

Posted - 2007-04-12 : 08:04:52
I am very new sql server but i need to write a SP which will contains one select stamet and one insert staement.I need to get value from select statment that i need to insert into other table?
here is my SP:

create PROCEDURE [dbo].[sp_geteventid](
@register_id int) AS

declare @eventid int
select event_id into @eventid from tbl_register where register_id =@register_id

insert into tbl_dummy values(@eventid)

Ho can i insert my event_id into tbl_dummy which i got from select statement

advanced thanks
Ram..

Cheers
Ram

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-12 : 08:09:36
use the INSERT INTO .. SELECT syntax


insert into tbl_dummy
select event_id
from tbl_register
where register_id = @register_id



KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-12 : 08:10:24
create PROCEDURE [dbo].[sp_geteventid](
@register_id int) AS

declare @eventid int
select @eventid = event_id from tbl_register where register_id =@register_id

insert into tbl_dummy values(@eventid)


or



create PROCEDURE [dbo].[sp_geteventid]
(
@register_id int
)
AS

insert tbl_dummy
SELECT event_id
from tbl_register
where register_id = @register_id



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-12 : 08:11:11
you better define the column name in the insert into column list

insert into tbl_dummy(column_name)
select event_id
from tbl_register
where register_id = @register_id



KH

Go to Top of Page

BuddyRam
Starting Member

17 Posts

Posted - 2007-04-12 : 08:14:14
Thank you very much i get ride off that..

Cheers
Ram
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2007-04-12 : 23:11:04
Sounds a lot like an interview question especially since its "urgent".

--Jeff Moden
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-04-13 : 01:39:49
how do you have time during an interview to post questions here?

or are there interviews with "take-home" questions?


www.elsasoft.org
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-13 : 02:17:30
My colleague once caught a candidate of mine, during an interview, asking a friend over the phone what the answer is.
The candidate said he needed to go to the men's room and my colleague was there too...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-13 : 03:42:27
See if you need these

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cmdr_skywalker
Posting Yak Master

159 Posts

Posted - 2007-04-13 : 13:38:55
Very Urgent?! It just amaze me of the audacity of such pachydermatous hominid to delude the magnanimity of chosen few with a fraud cry or poor choice of words. I wonder if the SP you gave came from your own labor or was the code from someone else too? Most people who cherish the labor of ones work will take some effort to exhaust all available resources on-hand (a.k.a. BOL, google) before asking someone's to give up their precious time to provide benevolent assistance. Check out R.E.S.P.E.C.T., you'll find it close with the phrase "OTHERS AS YOU RESPECT YOURSELF" :).



May the Almighty God bless us all!

www.empoweredinformationsystems.com
Go to Top of Page
   

- Advertisement -