Solved

Creating an Update stored procedure - SQL Server 2005

Posted on 2011-02-20
4
1,051 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 250 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 250 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

617 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