Solved

SQL 2005 Stored Procedure

Posted on 2008-06-17
4
257 Views
Last Modified: 2010-03-19
I am getting the following error message:
Msg 102, Level 15, State 1, Procedure InsertRMR, Line 8
Incorrect syntax near 'nvarchar'.
Msg 137, Level 15, State 2, Procedure InsertRMR, Line 18
Must declare the scalar variable "@".
My Srored Procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[InsertRMR]

@"site" nvarchar(50)=NULL,
@"date rec in PI" Datetime,
@"SS#" nvarchar(50)=NULL,
@"Description of Event" nvarchar(max),
@ "Originator" nvarchar,
@"date occured" Datetime,
@"date rec in PI" Datetime
As
Insert "dbo.RMR-FY08" ( "date rec in PI", site, "date occured", SS#, "description of event", originator)

Values ( @"date rec in PI", @"site", @"date occured", @"SS#", @"description of event", @originator)

Thanks for your help!





0
Comment
Question by:sandorka
[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
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 21807174
you cannot use spaces in variables...
ALTER Procedure [dbo].[InsertRMR] 
@site nvarchar(50)=NULL, 
@date_rec_in_PI Datetime, 
@SS nvarchar(50)=NULL,
@Description_of_Event nvarchar(max), 
@Originator nvarchar(max),
@date_occured Datetime,
@date_rec_in_PI Datetime 
As 
Insert into [dbo].[RMR-FY08] ( [date rec in PI], site, [date occured], [SS#], [description of event], originator) 
Values ( @date_rec_in_PI, @site, @date_occured, @SS, @description_of_event, @originator)

Open in new window

0
 
LVL 14

Assisted Solution

by:PockyMaster
PockyMaster earned 250 total points
ID: 21807467
even try to avoid spaces in columnNames as well. they're just annoying. (Also try to avoid underscores)

I prefer @dateRec instead. and e.g. DescriptionOfEvent for the column name.
Also try to avoid characters like #.
Use @SSNumber of something like that (probably SS means something as well..)

most of the time you want to SET NOCOUNT ON as well.

In Sql 2005 you have templates if you don't know what to do in some cases.

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21807490
<..>Also try to avoid underscores<...>
you make me curious about the "why" for avoiding underscores?
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 21807684
It has no performance reasons or whatsoever. It's a recommendation for .NET, it's easier to read, but of course, that's a matter of taste. Since lots of people generate code straight out of database schema's it will save you time stripping these underscores out and preventing CodeAnalysis warnings later.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

705 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