Solved

Incorrect syntax near 'outdated'.

Posted on 2004-09-13
9
532 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 18

Expert Comment

by:ShogunWade
ID: 12046132
" double quotes "    no dont use double quotes  i said 2 or these  '  together
0
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Insert to Begin if data exists 2 31
SQL Query 2 31
Dynamic SQL select query 4 36
Get Next number from Stored Procedure 8 22
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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 …
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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