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.
| Author |
Topic |
|
joshua__lim
Starting Member
1 Post |
Posted - 2008-03-27 : 06:41:01
|
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.quote: PROCEDURE [dbo].[usp_select_and_insert] @name varchar(20),ASSELECT phonenumber FROM USERLIST where OWNERNAME LIKE @nameINSERT 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. :) |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-27 : 06:46:54
|
Yes you can.INSERT INTO LOGLOG (destination,content)SELECT phonenumber, 'hello world' FROM USERLIST where OWNERNAME LIKE @name Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|