Solved

SQL 2005 Stored Procedure

Posted on 2008-06-17
4
244 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

808 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