Solved

Incorrect syntax near 'outdated'.

Posted on 2004-09-13
9
529 Views
Last Modified: 2008-01-09
I am using a BCP to write out information.  The problem I am having is that when I go to write out the information I get the error  
 Incorrect syntax near 'outdated'.

I know I have my sytax wrong, can someone tell me were?

thanks


 Set @script = 'BCP "SELECT distinct docsdb.dbo.vtab0010.val, docsdb.dbo.vtab0010.modified FROM docsdb.dbo.vtab0010, docsdb.dbo.temp where docsdb.dbo.vtab0010.val = docsdb.dbo.temp.val and  docsdb.dbo.temp.pdate <  docsdb.dbo.vtab0010.modified and  docsdb.dbo.temp.problem = 'outdated' "  queryout c:\' + @TabName + '.txt -U sa -P cfds -S -c'
0
Comment
Question by:running32
9 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 12045981
do you need the single quote in front of BCP?
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 12045988
you need to double up the quotes

ie:

instead of 'outdated'
put ''outdated''     (two single quotes each side)
0
 

Author Comment

by:running32
ID: 12046066
Yes, I need the single quote

and

No, the double quotes do not work when you put them around the word outdated.  When I do that I get:

usage: BCP {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-V file format version] [-q quoted identifier]
  [-C code page specifier]  [-t field terminator]    [-r row terminator]
  [-i inputfile]            [-o outfile]             [-a packetsize]
  [-S server name]          [-U username]            [-P password]

I'm not sure why it will not work it works when run just as a select statment.
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 12046132
" double quotes "    no dont use double quotes  i said 2 or these  '  together
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 18

Expert Comment

by:ShogunWade
ID: 12046140
after the assignment do PRINT @sql

and post the string
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 12046163
ok i think i see now.   there are two problems, one was masking the other.

try this

 Set @script = 'BCP "SELECT distinct docsdb.dbo.vtab0010.val, docsdb.dbo.vtab0010.modified FROM docsdb.dbo.vtab0010, docsdb.dbo.temp where docsdb.dbo.vtab0010.val = docsdb.dbo.temp.val and  docsdb.dbo.temp.pdate <  docsdb.dbo.vtab0010.modified and  docsdb.dbo.temp.problem = ''outdated'' "  queryout "c:\' + @TabName + '.txt" -U sa -P cfds -S -c'
0
 
LVL 6

Accepted Solution

by:
mcp111 earned 500 total points
ID: 12046457
Try this. You cannot use double quotes when embedding a string.

Set @script = 'BCP ''SELECT distinct docsdb.dbo.vtab0010.val, docsdb.dbo.vtab0010.modified FROM docsdb.dbo.vtab0010, docsdb.dbo.temp where docsdb.dbo.vtab0010.val = docsdb.dbo.temp.val and  docsdb.dbo.temp.pdate <  docsdb.dbo.vtab0010.modified and  docsdb.dbo.temp.problem = ''outdated''  queryout c:\' + @TabName + '.txt -U sa -P cfds -S -c'
0
 

Author Comment

by:running32
ID: 12046475
This is the output I receive when I use your example above.
with a print command

(556 row(s) affected)

BCP "SELECT distinct docsdb.dbo.vtab0010.val, docsdb.dbo.vtab0010.modified FROM docsdb.dbo.vtab0010, docsdb.dbo.temp where docsdb.dbo.vtab0010.val = docsdb.dbo.temp.val and  docsdb.dbo.temp.pdate <  docsdb.dbo.vtab0010.modified and  docsdb.dbo.temp.proble

0
 
LVL 7

Expert Comment

by:ChrisFretwell
ID: 12046550
Either your delcared length of @script is too short or you're only displaying the first 255 characters of the output.
If @script is more than 255 characters, then its just a setting in QA.

Go to tools , options, results and change Maximum characters per column to more than 255

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

17 Experts available now in Live!

Get 1:1 Help Now