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 |
|
label
Posting Yak Master
197 Posts |
Posted - 2003-04-04 : 10:28:24
|
and how do I fix it?This Stored Proc:quote: CREATE PROCEDURE dbo.ap_add_download_page@username varchar(50), @page_name varchar(50), @page_desc varchar(200)ASbegin set nocount on insert into download_pages (page_name, page_description, created_by, created_on) values (@page_name, @page_desc, (select userid from users where email=@username), getdate())End
Is giving me a "Subqueries are not allowed in this context. Only scalar expressions are allowed". I could have sworn I have down this type of thing before....but perhaps not. How can I do what I'm trying to do here?Thanks in advance. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-04-04 : 10:31:43
|
| CREATE PROCEDURE dbo.ap_add_download_page @username varchar(50), @page_name varchar(50), @page_desc varchar(200) AS begin set nocount on insert into download_pages (page_name, page_description, created_by, created_on) select @page_name, @page_desc, (select userid from users where email=@username), getdate()==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.Edited by - nr on 04/04/2003 10:32:14 |
 |
|
|
label
Posting Yak Master
197 Posts |
Posted - 2003-04-04 : 10:34:28
|
quote: insert into download_pages (page_name, page_description, created_by, created_on) select @page_name, @page_desc, (select userid from users where email=@username), getdate()
Thanks, worked perfectly! |
 |
|
|
Bambola
Posting Yak Master
103 Posts |
Posted - 2003-04-04 : 10:40:08
|
quote: insert into download_pages (page_name, page_description, created_by, created_on) values (@page_name, @page_desc, (select userid from users where email=@username), getdate())
(select userid from users where email=@username)you can take this part out of the query and insert the result into a variable. Take into consideration that if you have more than one matching row, the variable will contain the value of the last row.if you are sure there is only one, you can do the following:insert into download_pages (page_name, page_description, created_by, created_on) values (@page_name, @page_desc, (select TOP 1 userid from users where email=@username), getdate())Bambola. |
 |
|
|
|
|
|
|
|