August 28, 2018 at 7:21 am
Hi,
I am Trying to do a BCP export of a table. I am using the following that I got online:EXEC master..xp_cmdshell 'bcp "SELECT Dph_index,file_no,phone_no From DMPCNI.dbo.Star"
queryout "C:\Temp\Star2.csv" -c -T -S PS2016\DMP2'
This doesn't give an error when I run it, it just comes back with showing me the different options I can use (like -c, -t etc.); and it does not write to the file.
Any ideas what I am doing wrong here?
Thank you
August 28, 2018 at 9:34 am
I'm not sure about this particular command, but command options are usually case sensitive.
The output error seems to indicate the -t option should be lowercase.
You may want to try.
EXEC master..xp_cmdshell 'bcp "SELECT Dph_index,file_no,phone_no From DMPCNI.dbo.Star"
queryout "C:\Temp\Star2.csv" -c -t -s PS2016\DMP2'
August 28, 2018 at 9:38 am
August 28, 2018 at 9:39 am
Upon reading the article a bit, I'd point out that you need to use an uppercase '-S' to identify the server name.
August 28, 2018 at 9:42 am
Thanks but I tries that as well as other options and I still get the same thing, but thanks for your help, and I look at the link you provided.
Thanks
August 28, 2018 at 9:43 am
Also, the -t may not work without a separator arguement such as a comma. i.e. '-t,'
August 28, 2018 at 10:00 am
Thanks the link helped I got it to export, but for some reason it does not include the column names, Any idea what I can do there?
August 28, 2018 at 10:08 am
itmasterw 60042 - Tuesday, August 28, 2018 10:00 AMThanks the link helped I got it to export, but for some reason it does not include the column names, Any idea what I can do there?
Try changing your select to something like this. Of course, you may have to cast integer columns in your table to varchar type.
"select 'col1', 'col2',... union all select * from mytable"
August 28, 2018 at 10:41 am
Yah I seen a lot of people on line had that, and I tried it and but is then says that the BCP failed
August 28, 2018 at 10:42 am
This is what I had tried: SELECT Dph_index, file_no, phone_no UNION ALL SELECT Dph_index, file_no, phone_no FROM
August 28, 2018 at 11:48 am
itmasterw 60042 - Tuesday, August 28, 2018 10:42 AMThis is what I had tried:SELECT Dph_index, file_no, phone_no UNION ALL SELECT Dph_index, file_no, phone_no FROM
You need single quotes around the column names. Like this.
SELECT 'Dph_index', 'file_no', 'phone_no' UNION ALL SELECT Dph_index, file_no, phone_no FROM
August 28, 2018 at 12:48 pm
Jackie Lowery - Tuesday, August 28, 2018 11:48 AMitmasterw 60042 - Tuesday, August 28, 2018 10:42 AMThis is what I had tried:SELECT Dph_index, file_no, phone_no UNION ALL SELECT Dph_index, file_no, phone_no FROM
You need single quotes around the column names. Like this.
SELECT 'Dph_index', 'file_no', 'phone_no' UNION ALL SELECT Dph_index, file_no, phone_no FROM
This could be problematic unless ALL the actual column data has a varchar data type, as otherwise every data type in the table would have to be convertible to varchar implicitly.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
August 28, 2018 at 12:52 pm
sgmunson - Tuesday, August 28, 2018 12:48 PMThis could be problematic unless ALL the actual column data has a varchar data type, as otherwise every data type in the table would have to be convertible to varchar implicitly.
Right. I was just giving an example. He would have to use the correct method to convert each column.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply