C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

How to assign a query result to a stored procedure


Posted Date: 05 Nov 2009      Posted By: NekkantiDivya      Member Level: Gold     Points: 1   Responses: 2



Hi,
I my stored procedure I have an insert query. For this I have to get one value from a sub query. But it is not accepting that query. So I tried to declare a separate variable and assign the subquery value to this and insert it in the table.

Create Procedure [dbo].[AddOrRemoveFavourites]
(
@UserId bigint,
@VideoName varchar(50),
)
as

Declare @VideoId int
Set @VideoId = Select VideoId from Videos where Title='Monkeydog'

Insert into Favourites(UserId,VideoId) values(@UserId,@VideoId)


but in this I am getting error like "Incorrect syntax near the keyword 'Select'."

If anyone have any idea to solve this please reply me.

Thanks in advance.





Responses

Author: soniumesh    05 Nov 2009Member Level: GoldRating: 3 out of 53 out of 53 out of 5     Points: 3

Hi,

use this line as

Wrong : Set @VideoId = Select VideoId from Videos where Title='Monkeydog'

Right : Set @VideoId = (Select VideoId from Videos where Title='Monkeydog')

Regard,
umesh soni



Author: NekkantiDivya    05 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Thank you soniumesh.

It is working. Can you explain me the difference between those two queries



Post Reply
You must Sign In to post a response.
Next : Stored procedure in Mysql
Previous : COLLATE in SQL
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use