Skip to main content

Sql Server BCP(Bulk Copy Process) for Save file in csv format through stored procedure

Hi Techies,
           Today i am going to provide you a solutions for copy data from database and save that data in csv or any type of format in same or another location. 

So, For this type of work i used to BCP ( Bulk copy process ) using "xp_cmdshell" command in sql server. 

For this process we need Admin rights on SQL Server and xp_cmdshell access rights. 

After taking rights we have to write bellow query in stored procedure. 



--------------------------------------------------------------------------------------------------------------
--EXEC ExportTest
Create Proc ExportTest
AS
BEGIN    
    declare @cmd varchar(1000)
    set @cmd ='bcp "SELECT * FROM databasename.[dbo].[tablename]" queryout "C:\\FileTest\test.csv" -c -t , 
-S 10.XXXXXXXX -U username-P Password-T'
   exec xp_cmdshell @cmd
END

--------------------------------------------------------------------------------------------------------------

** You can use : \\machine name\Users\Desktop\ .... for shared location for different server.
** For Same Sytem : C:\\FileTest\test.csv  .. Simply use folder location.
** -S 10.XXXXXXXX -U username-P Password-T':  If you are using network server then use -S Database ServerName, -U database Username , -P database passwrod
** For local Database : Simply use (local) instead of ip and username and password.

If you have any query kindly write on comment box.
Thanks

Comments

Popular posts from this blog

MVC Interview Questions

MVC Interview Questions What is MVC Application life cycle ? What is default route in MVC? What is Output Caching ? What are Route Constraints in MVC? What are the Benefits of Area in MVC? How do you implement Forms authentication in MVC? What are the Main Razor Syntax Rules? Define attribute based routing in MVC? What are HTML helpers in MVC? What does the MVC pattern define with 3 logical layers? What are the advantages of MVC? List the various return types of a controller action method. What are the types of filters? What are the Filters in MVC? What are the three segments for routing important? What is Route in MVC? what is the difference between ViewData and ViewBag? attribute based routing in MVC? What is GET and POST Actions Types? What is MVC (Model view controller)? What is Validation Summary in MVC? What’s new in the latest version of MVC? How to render html in Asp.net MVC view? Explain the concept of MVC Scaffolding? What is Bundling and Mini...

Angular Step By Step Installation Process

# Angular Step By Step  Hello Techies,        In this post i am going to guide you to install Angular and create and run your first app. Please follow bellow steps.. Step 1 (Node NPM Installation) Node Js ( NPM)  should be installed on system. So for installation of Node Js follow bellow steps. Open  https://nodejs.org/en  .  Download stable Version (LTS) of Node js. After complete the installation open CMD and check the version. Step : 2 (Install Angular by NPM) Type " npm install -g @angular/cli "  2.  Select folder where you are going to create Angular Project.  3. Type ng new 'your app-name' EX:  ng new my-dream-app And Relax it will take some couple of minute to create app , because its downloading all the package from server by npm in you local system. Type : " cd my-dream-app " to select project which is created.  Now Type " ng serve " to run the project...

Azure Service Bus Vs Azure Web Job

MENU Home SUBSCRIBE Today, we will be talking about Azure service bus and how to use them with Webjobs. Azure Service Bus  is a messaging infrastructure that sits between applications allowing them to exchange messages for improved scale and resiliency. It offers the following capabilities: Queues: offers simple first in, first out guaranteed message delivery. When to use Azure Service Bus? Service Bus queues are a general-purpose technology that can be used for a wide variety of scenarios: Communication between web and worker roles in a multi-tier Azure application Communication between on-premises apps and Azure hosted apps in a hybrid solution Communication between components of a distributed application running on-premises in different organizations or departments of an organization There are also Topics and Relay capabiliteis but we will talk about them in the future. A figure that illustrates how Azure Service Bus works. There is a sender who send a mes...