Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using the recordset from SELECT statement in an INSERT statement, all in one Stored Procedure Expand / Collapse
Author
Message
Posted Thursday, March 27, 2008 4:59 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 4, 2010 8:02 AM
Points: 1, Visits: 5
Hi, i'm an SQL newbie. I'm trying to figure out if there's an easy way to take a single field record set from a SELECT statement and then do an INSERT using that record set, all in one single Stored Procedure.

Here's what i tried to do, but this returns an error "The name "phonenumber" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.".

The common field in both SELECT and INSERT is phonenumber.

PROCEDURE [dbo].[usp_select_and_insert]

@name varchar(20),

AS

SELECT phonenumber FROM USERLIST where OWNERNAME LIKE @name
INSERT INTO LOGLOG (destination,content) values(phonenumber,'hello world');

GO


Hope that one of you can be kind enough to give me some guidance. Appreciate in advance. :)
Post #475307
Posted Thursday, March 27, 2008 5:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:49 AM
Points: 5,367, Visits: 9,874
Something like this:

INSERT INTO LOGLOG (destination, [content])
SELECT phonenumber, 'hello world'
FROM USERLIST
where OWNERNAME LIKE @name

John
Post #475320
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse