473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SP Error

me
I'm trying to pass a filename and path into an sp and I'm getting an error.
I must be missing something easy. (Both UNC path and Drive letter path give
an error)
anyone know what might be the prob? (chars like : or \\ ????)

TIA

CBL
error is:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'J:'.

call to the sp is:
declare @ImportFile varchar(255)
--set @ImportFile='\\ACCT_NT\SHARED\CBL\ITEMTEST.txt'
set @ImportFile='J:\JOEL\ITEMTEST.txt'

EXEC shipping.dbo.pts_ImportItems @ImportFile
Jul 20 '05 #1
4 1429

"me" <me@work.com> wrote in message
news:10*************@corp.supernews.com...
I'm trying to pass a filename and path into an sp and I'm getting an error. I must be missing something easy. (Both UNC path and Drive letter path give an error)
anyone know what might be the prob? (chars like : or \\ ????)

TIA

CBL
error is:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'J:'.

call to the sp is:
declare @ImportFile varchar(255)
--set @ImportFile='\\ACCT_NT\SHARED\CBL\ITEMTEST.txt'
set @ImportFile='J:\JOEL\ITEMTEST.txt'

EXEC shipping.dbo.pts_ImportItems @ImportFile


You'll have to show the procedure code where the variable @ImportFile is
used - as a complete guess, you're building a string dynamically, and the
execution of that string is giving the error. If this is the case, you may
want to SELECT the string just before you execute it, to make sure it's
doing what you think it is - it's convenient to add a @Debug parameter to
the procedure to do this, so you can easily troubleshoot in future. But I
might be completely wrong, since you haven't posted any detailed code.

Simon
Jul 20 '05 #2
me
Here is probably where the problem is per your suggestion the actual sp code
follows:
exec ('BULK INSERT SHIPPING.DBO.ItemTest FROM '+ @ImportFile +' WITH
(FORMATFILE ='+ @FormatFile +')')

here is the sp code:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE pts_ImportItems(@ImportFile varchar(255))
AS
SET NOCOUNT ON

DECLARE @ErrorSave int
declare @Barcode int
declare @FormatFile varchar(255)

--set @ImportFile='\\ACCT_NT\SHARED\CBL\ITEMTEST.txt'
set @FormatFile='\\ACCT_NT\SHARED\CBL\ITEMTEST.fmt'

BEGIN TRANSACTION

if exists (select * from dbo.sysobjects where id = object_id(N'[ItemTest]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [ItemTest]

/*change to a temp table when working and delete the drop table*/
CREATE TABLE [ItemTest] (
[BarCode] [int] IDENTITY(1,1) NOT NULL ,
[FileNumber] [nvarchar] (20) NULL CONSTRAINT [DF_ItemTest_FileNumber]
DEFAULT (''),
[ItemNumber] [nvarchar] (50) NULL CONSTRAINT [DF_ItemTest_ItemNumber]
DEFAULT (''),
[Description] [nvarchar] (50) NULL CONSTRAINT [DF_ItemTest_Description]
DEFAULT (''),
[RoomNumber] [nvarchar] (50) NULL CONSTRAINT [DF_Item_RoomNumber] DEFAULT
(''),
[Quantity] [int] NULL CONSTRAINT [DF_ItemTest_Quantity] DEFAULT ('0'),
[ImportDate] [datetime] NULL CONSTRAINT [DF_ItemTest_ImportDate] DEFAULT
(getdate()),
CONSTRAINT [IX_ItemTest] UNIQUE NONCLUSTERED
(
[BarCode]
) ON [PRIMARY]
) ON [PRIMARY]

exec ('BULK INSERT SHIPPING.DBO.ItemTest FROM '+ @ImportFile +' WITH
(FORMATFILE ='+ @FormatFile +')')

set @Barcode=dbo.pts_GetNextBarcode2()

insert Item2 ([BarCode Part#],[File Number],[Item
Number],[Description],[Room Number],[Quantity])
select
[BarCode]+@Barcode,
[FileNumber],
[ItemNumber],
[Description],
[RoomNumber],
[Quantity]
from
dbo.ItemTest

SELECT @ErrorSave = @@ERROR

IF @ErrorSave <> 0
ROLLBACK TRANSACTION
ELSE
COMMIT TRANSACTION

RETURN @ErrorSave
GO

SET QUOTED_IDENTIFIER OFF
GO

SET ANSI_NULLS ON
GO

"Simon Hayes" <sq*@hayes.ch> wrote in message
news:40********@news.bluewin.ch...

"me" <me@work.com> wrote in message
news:10*************@corp.supernews.com...
I'm trying to pass a filename and path into an sp and I'm getting an

error.
I must be missing something easy. (Both UNC path and Drive letter path

give
an error)
anyone know what might be the prob? (chars like : or \\ ????)

TIA

CBL
error is:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'J:'.

call to the sp is:
declare @ImportFile varchar(255)
--set @ImportFile='\\ACCT_NT\SHARED\CBL\ITEMTEST.txt'
set @ImportFile='J:\JOEL\ITEMTEST.txt'

EXEC shipping.dbo.pts_ImportItems @ImportFile


You'll have to show the procedure code where the variable @ImportFile is
used - as a complete guess, you're building a string dynamically, and the
execution of that string is giving the error. If this is the case, you may
want to SELECT the string just before you execute it, to make sure it's
doing what you think it is - it's convenient to add a @Debug parameter to
the procedure to do this, so you can easily troubleshoot in future. But I
might be completely wrong, since you haven't posted any detailed code.

Simon

Jul 20 '05 #3

"me" <me@work.com> wrote in message
news:10*************@corp.supernews.com...
Here is probably where the problem is per your suggestion the actual sp code follows:
exec ('BULK INSERT SHIPPING.DBO.ItemTest FROM '+ @ImportFile +' WITH
(FORMATFILE ='+ @FormatFile +')')

here is the sp code:


<snip>

If you check the examples in Books Online, you'll see that the filename has
single quotes around it:

.... FROM 'f:\orders\lineitem.tbl' ...

But your variable substitution will not have any quotes:

.... FROM \\ACCT_NT\SHARED\CBL\ITEMTEST.txt ...

So you need to add them:

exec ('BULK INSERT SHIPPING.DBO.ItemTest FROM '''+ @ImportFile +''' WITH
(FORMATFILE ='''+ @FormatFile +''')')

(That's 3 single quotes in each case, in case your font isn't quite clear).
An easier way to troubleshoot this is:

declare @sql nvarchar(1000)
set @sql = 'BULK INSERT SHIPPING.DBO.ItemTest FROM '''+ @ImportFile +'''
WITH (FORMATFILE ='''+ @FormatFile +''')'
if @debug = 1 print @sql
exec(@sql)

Now you can add a parameter to your procedure called @debug:

@debug bit default 0

If you get strange syntax errors, you can execute the procedure like this,
and you will see the SQL string, which will hopefully make the problem more
obvious:

EXEC shipping.dbo.pts_ImportItems @ImportFile = 'c:\temp\in.txt', @debug = 1

Simon
Jul 20 '05 #4
me
Thanks! I should have looked at the quotes closer...the @debug var is a
good idea too I've had a lot of trouble trying to debug in the past.

Carter

"Simon Hayes" <sq*@hayes.ch> wrote in message
news:40**********@news.bluewin.ch...

"me" <me@work.com> wrote in message
news:10*************@corp.supernews.com...
Here is probably where the problem is per your suggestion the actual sp code
follows:
exec ('BULK INSERT SHIPPING.DBO.ItemTest FROM '+ @ImportFile +' WITH
(FORMATFILE ='+ @FormatFile +')')

here is the sp code:


<snip>

If you check the examples in Books Online, you'll see that the filename

has single quotes around it:

... FROM 'f:\orders\lineitem.tbl' ...

But your variable substitution will not have any quotes:

... FROM \\ACCT_NT\SHARED\CBL\ITEMTEST.txt ...

So you need to add them:

exec ('BULK INSERT SHIPPING.DBO.ItemTest FROM '''+ @ImportFile +''' WITH
(FORMATFILE ='''+ @FormatFile +''')')

(That's 3 single quotes in each case, in case your font isn't quite clear). An easier way to troubleshoot this is:

declare @sql nvarchar(1000)
set @sql = 'BULK INSERT SHIPPING.DBO.ItemTest FROM '''+ @ImportFile +'''
WITH (FORMATFILE ='''+ @FormatFile +''')'
if @debug = 1 print @sql
exec(@sql)

Now you can add a parameter to your procedure called @debug:

@debug bit default 0

If you get strange syntax errors, you can execute the procedure like this,
and you will see the SQL string, which will hopefully make the problem more obvious:

EXEC shipping.dbo.pts_ImportItems @ImportFile = 'c:\temp\in.txt', @debug = 1
Simon

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
0
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.