Solved

Creating an Update stored procedure - SQL Server 2005

Posted on 2011-02-20
4
1,044 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 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 45

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now