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
 General SQL Server Forums
 Database Design and Application Architecture
 Stored Procedures - Insert Data gathered from Sele

Author  Topic 

Kickaboo
Starting Member

10 Posts

Posted - 2008-03-28 : 13:07:45
Hi,

I am trying to write a stored procedure, which does a couple of things.

First thing is it looks up a persons Location based on an ID number, which is passed from an external Script. This will return four Values from a table.

I want to insert those four values into another table, along with another ID passed to the procedure from the same script.

My question is, what do I do to the script below to get the four values out of the first look up, into the insert?

The Field names returned from the SELECT are, AREA1, AREA2, AREA3, AREA4

Thanks

David


CREATE PROCEDURE UserAssign_Location

@UserID Int, @AreaID Int
AS
BEGIN
SET NOCOUNT ON;

SELECT * From Locations Where EntryID = @AreaID

INSERT INTO Members_Locations (UserID, Location1, Location2, Location3, Location4, Active)
VALUES (@UserID, 'AREA1', 'AREA2', 'AREA3', 'AREA4', 1)

END
GO


jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-03-29 : 07:32:37
CREATE PROCEDURE UserAssign_Location

@UserID Int, @AreaID Int
AS
BEGIN
SET NOCOUNT ON;



INSERT INTO Members_Locations (UserID, Location1, Location2, Location3, Location4, Active)
SELECT @userID as userID,AREA1,AREA2,AREA3,AREA4,1 From Locations Where EntryID = @AreaID
END
GO

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -