Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating an Update stored procedure - SQL Server 2005

Posted on 2011-02-20
4
Medium Priority
?
1,054 Views
Last Modified: 2012-05-11
I'm trying to create a stored procedure which will update a single record in a table. The code below is not working. Any advice would be appreciated.
USE [D:\MOVIESDB\MOVIEDB.MDF]
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE usp_update_movie
(@ID int,
 @Title varchar(50),
 @Director varchar(50),
 @YearReleased smallint,
 @Genre varchar(50),
 @Stars smallint,
 @Plot varchar(100),
 @IsDVD varchar(10),
 @RunTime smallint,
 @Rating varchar(10),
 @Picture varchar(50))
AS
SET NOCOUNT ON;

UPDATE tblMovies
SET 
Title=@Title,
Director=@Director,
YearReleased=@YearReleased,
Genre=@Genre,
Stars=@Stars,
Plot=@Plot,
IsDVD=@IsDVD,
RunTime=@RunTime,
Rating=@Rating,
Picture=@Picture)

WHERE MovieID = ID

Open in new window

0
Comment
Question by:98fatboyrider
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1000 total points
ID: 34938302
Your where clause is wrong missing the @ before ID, chenge to :

WHERE MovieID = @ID
0
 

Author Comment

by:98fatboyrider
ID: 34938338
Thanks Jacko, I missed that.
I'm still getting the error below. Why I don't know.

"Msg 102, Level 15, State 1, Procedure usp_update_movie, Line 28
Incorrect syntax near ')'."
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 1000 total points
ID: 34938359
remove the closing bracket from here :

Picture=@Picture)
0
 
LVL 46

Expert Comment

by:aikimark
ID: 34938371
You have an extraneous right parenthesis character.

Change this

Rating=@Rating,
Picture=@Picture)

Open in new window


To this

Rating=@Rating,
Picture=@Picture

Open in new window

0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question