Can't use bcp in SQL Server procedure

I need to export data of sales between the last 4 years to a csv using a stored procedure, however the output of that just gives User
name not provided, either use -U to provide the username or use -T for Trusted Connection, then it gives the possible parameters to
give to the command. What am I typing wrong? I've double checked the servername and i'm using -T.
select
dateSales, Sales
into ##temp
from
dbo.Sales
where
dateSales between convert(varchar(20), year(DATEADD(YEAR, -4, getdate())))+'-01-01' AND getdate();
select * from ##temp;
EXEC xp_cmdshell 'bcp "select * from ##temp" queryout "C:\Users\PatriceW\Documents\sales.csv" -c -T -SSQLserver -t, -r\r\n'
Thank you in advance.

Unfortunately I can't reproduce it in my local.
I tried belwo 2 in SSMS and also in Command prompt and both worked -
EXEC xp_cmdshell 'bcp "select * from ##temp" queryout "C:\temp\sales.csv" -c -T'
EXEC xp_cmdshell 'bcp "select * from ##temp" queryout "C:\temp\sales.csv" -c -T -S localhost'
My BCP is inside C:\Program Files\Microsoft SQL Server\100\Tools\Binn.
Few things to check:
Ensure if the folder exists and you have permission to write to it. Try giving some local path.
Try running the bcp from SSMS and CMD both. If it runs from CMD then SQL Server account has no permissions
Do consider reading Permissions, Remarks section given in below:
 https://msdn.microsoft.com/en-us/library/ms162802.aspx
-Vaibhav Chaudhari

Similar Messages

  • How to load decimal values into a file using bcp in SQL Server 2000?

    Hi everyone,
    I'm trying to load data from a database table to a text file using bcp on SQL Server 2000. When I'm loading the decimal values, the values before the decimal are not being loaded into the file. How could I load the values before decimals?
    Here are the DDLs and DMLs of what I'm trying to run:
    CREATE TABLE [dbo].[Product_Sales](
    [Year_of_Sale] [smallint] NOT NULL,
    [Product_Type] [varchar](25) NOT NULL,
    [Product_Group] [varchar](25) NOT NULL,
    [Category_Type] [varchar](25) NOT NULL,
    [Category_Group] [varchar](10) NOT NULL,
    [Product_Count] [bigint] NOT NULL,
    [Product_Amount] [decimal](19, 2) NOT NULL,
    [Category_Count] [bigint] NOT NULL,
    [Category_Amount] [decimal](19, 2) NOT NULL,
    CONSTRAINT [PK_Product_Sales] PRIMARY KEY CLUSTERED
    [Year_of_Sale] ASC,
    [Product_Type] ASC,
    [Product_Group] ASC,
    [Category_Type] ASC,
    [Category_Group] ASC
    ) ON [PRIMARY]
    ) ON [PRIMARY]
    INSERT INTO [Yearly_Sales].[dbo].[Product_Sales]
    VALUES(2010, 'Online', 'Web', 'Cameras', 'Electronics', 547, 0.00, 0, 0.00)
    EXEC [master].[dbo].[xp_cmdshell] 'bcp "SELECT * FROM [Yearly_Sales].[dbo].[Product_Sales]" queryout D:\Yearly_Sales\Product_Sales.dat -c -T -S'
    And the output I see in the file is:
    2010 Online Web Cameras Electronics 547 .00 0 .00
    The values before decimals are being truncated.
    Thanks,
    Bangaaram
    Known is a DROP, Unknown is an OCEAN.

    You can modify the decimal column(s) in the table to varchar type before export. But it does not look good.
    alter table [dbo].[Product_Sales]
    Alter column [Product_Amount] varchar(20)
    alter table [dbo].[Product_Sales]
    Alter column [Category_Amount] varchar(20)
    Does that make any sense?
    Known is a DROP, Unknown is an OCEAN.
    Basically you modify the decimal column to a varchar type before you run the bcp command for export. You can modify your source table or you can modify them on the fly. It is just a workaround.
    Modifying the source wouldn't be a good idea. Never do that if you can't get your desired output.
    Known is a DROP, Unknown is an OCEAN.

  • Can I use Built-in SQL Server in Visual Studio 2010 ?

    Hi Friends, I am Atif.
    If I will upload my project to my Server Domain and I want to use Built-in Visual Studio 2010 Sql Server Expreess Database then it will work. If yes then Please suggest me How..??
    Actually I don't want to install SQL Server Database Seperately.
    Tell me How can i achieve this.
    Thanks and Regards.
    Atif.

    Hi Atif,
    Besides other post, to use SQL Server Express for development work, you just need to specify the data source (SQL server's name) and authentication details in a connection string. For more information about SQL Server Express connection string, you can review
    the examples in the following articles.
    Database Connectionstrings
    SQL Server Connection Strings for ASP.NET Web Applications
    Also please note that SQL Server Express edition has some limitations, for example: only one CPU can be used by the express edition, the maximum size of a database is 4 GB (10GB in SQL Server 2008 R2 Express and higher versions of SQL Server Express),
    it can only use up to 1GB of RAM.
    Thanks,
    Lydia Zhang
    Lydia Zhang
    TechNet Community Support

  • Can I use Java with SQL Server CE edition?

    Hi,
    Can anybody tell me whether I can use Java to program the database operations for SQL Server CE?

    Hi:
    I have the same question. I don't know java how to connect the Microsoft SQL Server CE. Do you know the answer now? Please let me know. Thank you very much.
    chia-li
    [email protected]

  • XDK APIs (C/C++/Java) and tools can also  be used with MS SQL Server

    I want to know if XDK APIs (Java or C/C++ APIs especially) and tools can be used with MS SQL Server or not?
    I want to write a simple application that updates XML ( acordXML used for insurance) document into SQL Server tables. Of course I am assuming to transform into appropriate XSU APIs format.

    No. Use SQLXML instead on a SQL Server.

  • Error executing MS sql server procedure

    I am getting an error below while executing a SQL server procedure from SOA composite. My jdeveloper and Soa Suite version is 11.1.1.4.
    I am using “Oracle’s MS SQL Server Driver (Type 4) Version: 7.0 and later” driver. The SQL Server version is 2005.
    To configure the connection I used the steps mentioned in URL below.
    http://beatechnologies.wordpress.com/2011/01/31/creating-a-dbadapter-for-mssql-server-in-osb-11g/
    The MS SQL procedure signature is as below.
    @p_EventId               nvarchar     IN
    @p_EventName_IN               nvarchar     IN
    @p_Agreement_No_IN          decimal          IN
    @p_Acc_Base_Number_IN          decimal          IN
    @p_Acc_Comp_No_IN          decimal          IN
    @p_Account_Company_Name_IN     nvarchar     IN
    @p_Agree_Stat_Code_IN          nvarchar     IN
    @p_Agree_Type_Code_IN          nvarchar     IN
    @p_HeadQtr_Code_IN          nvarchar     IN
    @p_Sales_Off_Name_IN          nvarchar     IN
    @p_Reseller_Name_IN          nvarchar     IN
    @p_Oracle_Order_number_IN     decimal          IN
    @p_License_Effective_Date_IN     datetime     IN
    @p_PO_Number_IN               decimal          IN
    @p_Invoice_Number_IN          decimal          IN
    @p_Invoice_Date_IN          datetime     IN
    @p_Support_Contract_ID_IN     decimal          IN
    @p_Stmt_Of_Capacity_Due_Date_IN     datetime     IN
    @p_Contract_Start_Date_IN     datetime     IN
    @p_Contract_End_Date_IN          datetime     IN
    @p_Contract_Type_IN          nvarchar     IN
    Error message .
    <fault>
    <bpelFault>
    <faultType>0</faultType>
    <bindingFault>
    <part name="summary">
    <summary>Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'CompanySPProdcall' failed due to: Unimplemented object conversion. Conversion of type 1 whose JDBC type is OTHER to a Java object is not supported. An attempt was made to convert type 1 to a Java object using an unsupported JDBC type: OTHER. Use a data type with a supported JDBC type. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. </summary>
    </part>
    <part name="detail">
    <detail>Unimplemented object conversion. Conversion of type 1 whose JDBC type is OTHER to a Java object is not supported. An attempt was made to convert type 1 to a Java object using an unsupported JDBC type: OTHER. Use a data type with a supported JDBC type. </detail>
    </part>
    <part name="code">
    <code>null</code>
    </part>
    </bindingFault>
    </bpelFault>
    </fault>
    Please let me know the solution for this issue?
    Thanks...

    I had the similar problem and I am using 11.1.1.5.
    When I changed the platformClassName to org.eclipse.persistence.platform.database.SQLServerPlatform it worked.
    You can find platformClassName in Outbound Connection Properties
    Hope this might work :)

  • Problem accessing Sql server Procedure from Crystal with JDBC driver

    I have some Crystal reports using SQL Server procedures, most of them are working very well; however, I have 2 that have problems accessing sql server procedures. These reports are working using OLE DB connection without problem, but when I try to relocate the connection to JDBC Crystal generates an error like that the procedure not return records.
    The procedure is working with other products including OLE DB connections from crystal.
    What can I do?
    Thanks in Advance,
    JaimeC

    I am using:
    Crystal report 11 - 11.0.0.1282 and Crystal 2008 = 12.0.0.683
    SQL Server 2005 -  Microsoft SQL Server Management Studio Express     9.00.4035.00
    Windows XP
    I have discovered that the procedures create and work  temporary tables. In other cases when is working ok, the procedures have not working temporary tables.
    Thanks,
    Jaime Carrillo

  • Migrate MS SQL Server procedure to Oracle

    Can any one suggest me any user friendly tool to Migrate MS SQL Server procedure to Oracle. I think using OMWB we can migrate schemas, as i could not find any interface to migrate a single procedure

    I tried using swisssql, but the trial version only migrates 10 tables and 10 indexes and no other objects. Is there any other tool which shall migrate only procedures? If so plz suggest me.....

  • SQL Server Procedures Questions

    Hello,
    I needed some simple help in SQL Server, given below are my two questions.
    I am looking at making a SQL Server Procedure which uses cursors to detect some data entry 
    mistakes. 
    1) I have a query joining two or three tables and returning me a list of rows. I would like to compare the Name column in this list using a like operator and report back any names which are similar. How can this be done ? If possible please send me a brief
    skeletal code to do the same.
    2) I am using a query to join names of employees with languages they speak. The query works fine but for employees who speak more than 1 language, the record gets repeated with a new line for every new language they speak, instead of doing this, I would
    like to concatenate their languages in 1 column and report back 1 row per employee. Is this possible ?
    If yes please send me the brief skeletal code to do this on [email protected]
    Thanks
    Irfan

    >> If yes please send me the brief skeletal code to do this on [email protected]
    Good day Irfan
    This is not a paid supporting center, where you get private support, by commercial company, but a public forum where communities members helps each other. Public posts, answers, and discussions have a huge advantage! Other people might learn from the thread
    as well.
    >> I have a query joining two or three...
    Please check Tom
    Cooper's answer, and if this is not what you are looking for, then please post more information and less stories (I mean codes). Please show us the query instead of describe it. the code describe it better :-) Moreover, pls post DDL+DML
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.

    Hello All,
    I am getting below error can you please help me
    Error:-
    The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.

    Perhaps this thread will help you out
    http://stackoverflow.com/questions/11453066/error-the-transaction-associated-with-the-current-connection-has-completed-but
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Create Fiat File Using Trigger in SQL Server

    Dear All,
        How to Create a Flat File using Trigger in SQL Server?

    Take a look at osql/sqlcmd, bcp, COM calls, xp_cmdshell, etc.  Here are a few links with code examples:
    https://www.simple-talk.com/sql/t-sql-programming/reading-and-writing-files-in-sql-server-using-t-sql/
    http://www.nigelrivett.net/SQLTsql/WriteTextFile.html
    http://stackoverflow.com/questions/8132663/creating-a-text-file-on-local-machine-using-sql-server-2008
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How save & retrive data from database using flex, coldfusion, sql server

    hi , i am very new in flex, i am trying to insert data in
    database using flex2, coldfusion, sql server. any one can help me
    please. or give me any example.

    Hi try to goto the following sites, you will get some
    direction to think
    http://weblogs.macromedia.com/pent/archives/2006/11/example_of_flex.cfm
    http://pdxphp.org/node/258
    Good Luck

  • Can I recover a damaged SQL Server 2008 database with the undamaged .mdb and .ldf files?

    Their original SQL Server was 2008, with SP unknown, but installed on D: and C: drives.  The power spike corrupted their O/S on the C:
    drive and someone reinstalled both the O/S and the SQL Server, which is now SQL 2008, SP4.  They have intact files for all system databases, both .mdb and .ldf.  Is there some way they can reconnect with the user databases using the intact copies
    of the previous system databases? I have heard that if the SQL Server is stopped, previous Master and Msdb .mdb and .ldf files moved into place and the server restarted, that any previous user database .mdb and .ldf files can be accessed by the SQL server.
    Is this the case, or are there details missing?

    Hello! try this steps
     1 Open your SQL Server Management Studio console. This application shortcut is available in the SQL Server directory in the Windows Start button.
    2  Enter the system administrator user name and password. SQL Server's administrator user name is "sa." This account is required for privileges to restore the database. If your restoring on a host provider server, use the administrator user name
    and password they supplied for your account.
     3 Right-click your database name and select "Attach." In the new window that opens, click the "Add" button to open a dialog box.
     4 Select your MDF file and press the "Ok" button. It may take several minutes to restore the database if it is a large file. Once the process is finished, browse your tables to verify the data. The database is now restored.
    If nothing helped try to use: 
    https://www.youtube.com/watch?v=1cbOYdvBW2c

  • SQL Server procedure migration

    I have a few SQL Server procedures that return multiple rows. How can I change them to be handled correctly by Oracle?

    Oracle8i JDBC Developer's Guide and Reference
    Release 2 (8.1.6) A81354-01 http://technet.oracle.com/doc/oracle8i_816/java.816/a81354/samapp5.htm#1016413 contains a jdbc example program shows Oracle JDBC REF CURSOR functionality
    Turloch
    Oracle Migration Workbench Team

  • How to convert sql server procedure in to plsql procedure

    hi guys
    i have requirement where in i have to convert sql server procedure into plsql procedure.
    can some one help me out .
    thanks,
    Vamshi.D

    Hi Vamshi,
    As you want to convert sql server procedure in to plsql procedure
    i.e SQL SERVER ->ORACLE Right
    FYI
    SQL SERVER Proc. Syntax are totally different as compared to ORACLE Proc.
    So, better you study Logic of SQL-SERVER Proc and convert into
    Oracle Procedure.
    Thanks,
    Samadhan

Maybe you are looking for

  • User Profile Incremental Sync does not views changes in profiles.

    User Profile Incremental Sync does not views changes in profiles. I make full sync - all ok. then I change the phone number for example, and then start incremental sync and nothing moves to AD.  All the stages of FIM sync just state 0 records to proc

  • Manual addition of line item allowed in Outbound delivery

    Dear Experts,          In the "Outbound delivery" document created with reference to "sales Order" if we tried to add one more line item manually then, system is accepting that line item without any warning / error message.             but as per our

  • BPEL Process with multiple file types using one FTP adapter is not working

    i created a bpel process which will fetch the files from remote location using FTP adapter. Now the process works for only one format or file type like *.xls. How can i use more than one file format in one FTP adapter. OR is there any other way to do

  • Display logged in user name in omniportlet

    I am getting error when I use portal.wwctx_api.get_user() in sql query in omniportlet. I saw a solution in the forum that I needed to create page parameter and get the user name in th epage parameter and use that parameter in omniportlet My question

  • Burning Double Layer DVDs in iDVD 6.0.3

    I can't seem to burn double layer DVDs. I am using an intel iMac which says i should be able to but it won't accept discs to burn. Is it because i am using 8.5GB discs because iDVD says in the project info that double layer DVD should be 7.7GB? Any t