Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

BCP - Export data to Text File

Aug 27 2007 9:30AM by Madhivanan   

Here is a simple method of exporting all the data from SQL Server table to a Text File

CREATE Procedure BCP_Text_File
(  
@table varchar(100),  
@FileName varchar(100)  
)  
as  
If exists(Select * from information_Schema.tables where table_name=@table)
    Begin
        Declare @str varchar(1000)  
        set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'+@table+'" queryout "'+@FileName+'" -c'''  
        Exec(@str)  
    end
else
    Select 'The table '+@table+' does not exist in the database'

Execute this procedure by giving Table Name and the File Name

EXEC BCP_Text_File 'Employee','C:\emp.txt'

Now all the data from Employee table will be exported to the text file which will be located at C:\emp.txt

Tags: t-sql, sql_server, bcp, export_to_text,


Madhivanan
3 · 40% · 12862
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • Hi,

    I am loading some pipe delimited files in a sql table through BCP. Can you give us some example for its error handling in T-sql?

    I searched it a lot, but didn't find anything better to catch the error.

    Thanks, preru

    commented on Aug 24 2011 12:01AM
    preru
    3016 · 0% · 2

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]