473,326 Members | 2,126 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,326 software developers and data experts.

SQL Query to text file "WHERE" syntax

Hey guys,

I know there have been plenty of posts on this topic. I did my research and have my Query outputting to a text file as I wanted. However I have a question with adding something to my command.

Here is my command that is working:

EXEC XP_CmdShell 'BCP "Select code, desc From DATABASE.dbo.table" queryout "C:\test.txt" -c -T'



I want to add a "WHERE" command to this line, where I have a value equal to something...Example:

WHERE mat = '8888'



I know I need to declare "mat" as part of a different table in the database. Here is what I have at the moment...

EXEC XP_CmdShell 'BCP "Select code, desc From DATABASE.dbo.table, DATABASE.dbo.OtherTable b WHERE b.mat = '8888'" queryout "C:\test.txt" -c -T'

I am getting a syntax error where '8888' is. I know it is because of the ' character that is commenting out my equal to value. What is the correct syntax to do this? I have tried many things and still haven't gotten it to work. Any help is appreciated! Thanks everyone!
Nov 15 '11 #1
1 1378
ck9663
2,878 Expert 2GB
Instead of one single quote before and after the 8888, use two single quote. Lave the double-quote to enclose the query.

Happy Coding!!!


~~ CK
Nov 15 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
4
by: atse | last post by:
Hi, I tried to make select query to a text file using the code below, <% sconnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="D:\myforlder\;Extended...
12
by: alessia | last post by:
hi, I have a query that visualizes me, according to some criterions from me inserted, name , Surname , Address , phone ok.. Now, through a button, positioned in a Form, I have to only export...
6
by: MLH | last post by:
I was able to do this from Access 2.0. It had to be set up, of course, but it could be done. I'm unsure as to why Access 97 says "Can't find file"??? ...
2
by: garth.waring | last post by:
Hi all I have seen the In Clause used to remotely query a text file done but cannot find the right syntax The example below is for an excel file : SELECT * FROM IN...
5
by: kutty | last post by:
Hi All, I am loading data to a child table from a text file. the text files also contains data not referenced by parent key. while loading the data if one row fails to satisfies the constraint...
2
by: nuhura01 | last post by:
Hi.. I'm trying to save query path which is in text box to text file. Below is the coding that i'm using currently: Private Sub SaveQueryPath() 'save to text file Response.Clear()...
12
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql...
3
by: Wayne | last post by:
I'm trying to automate the export of a query to a text file using code. If I export the query manually I get the exact result that I want i.e. If I select the query then choose File/Export from...
8
by: iheartvba | last post by:
Hi I am using Access 2007 and am trying to export a query to a fixed length text file. I tried using the following code to export the text file: DoCmd.TransferText acExportFixed, , "qryFFRDeFile",...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.