Solved

SQL 2005 Stored Procedure

Posted on 2008-06-17
4
236 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 142

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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

777 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