Help Needed in BCP Command

  • Hi,

    I am trying to export my table data into Textfile using BCP command.

    Below is my query to do that.

    EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT N from sample.dbo.tally" queryout C:\Report.txt -t"|" -c -T '

    ServerName : Resdox-0043\KGJ-DEV

    UserName : Sa

    Password : Pasword123

    when i try to run this query i am getting error as follows

    NULL

    Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT SERVICE\MSSQL$KGJ-DEV'.

    SQLState = 28000, NativeError = 18456

    Am i doing something wrong? am i missing something on the parameter to the BCP command? please help m on this

  • Ok, After browsing the web i found and i tried with the below option.

    EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT N from sample.dbo.tally" queryout D:\Report.txt -N -S Resdox-0043\KGJ-DEV -U sa -P Pasword123'.

    i tried to export. here is the result

    NULL

    Starting copy...

    1000 rows successfully bulk-copied to host-file. Total received: 1000

    1000 rows successfully bulk-copied to host-file. Total received: 2000

    NULL

    2000 rows copied.

    Network packet size (bytes): 4096

    Clock Time (ms.) Total : 1 Average : (2000000.00 rows per sec.)

    NULL

    I have 2000 rows in my table and the output shows 2000 rows copied. but if i open the generated text, i could see the junk data

    § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ

    ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p

    Any suggestions please

  • Finall i am able to achieve with the below line,

    queryout D:\Report.txt -T -c -t, -b 100 -S Resdox-0043\KGJ-DEV -U sa -P Pasword123

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply