Solved

SQL 2005 Stored Procedure

Posted on 2008-06-17
4
217 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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
execute a MS SQL script as a schedule SQL job 72 101
MS SQL Backup 24 70
sql server query? 6 28
Access recordset not updateable 8 39
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

746 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

12 Experts available now in Live!

Get 1:1 Help Now