Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 export data from sql server 2005 table to text fil

Author  Topic 

mpolaiah
Starting Member

24 Posts

Posted - 2009-08-05 : 14:26:49
Hi All,

i am using the sqlcmd -d expot the data into text file at save the file 186.txt
and once again run the sqlcmd -d and save the same path i loss the previous data
and save the new data.


but i want prevous data also it is possible .....................like

i am run the sqlcmd -d first time........................

declare @SQLCmd varchar(500),
@FilePath varchar(200),
@nRequestid varchar(100)
set @nRequestid=186
--set @DBName='SMS'
--set @TableName='AH_PRE_REQUEST_DETAILS'
set @FilePath='F:\polo\'+@nRequestid+'.txt'

--set @Separator='#'
SET @SQLCmd ='sqlcmd -d SMS -Q "set nocount on;Select * From AH_PRE_REQUEST_DETAILS where nrequestid='+@nRequestid +'" -o "' + @FilePath + '" -W -s "' + '#' + '" -h -1'
EXEC master..xp_cmdshell @SQLCmd

i got the text file result is:

10#186#919985339980#hiii#N#NULL#N#NULL#NULL
11#186#919966402076#hiii#N#NULL#N#NULL#NULL
12#186#919885900681#hiii#N#NULL#N#NULL#NULL
13#186#919963791113#hiii#N#NULL#N#NULL#NULL
14#186#919989912348#hiii#N#NULL#N#NULL#NULL


once again i run

15#187#919985339980#Suneel hi 9985339980#N#NULL#N#NULL#NULL
16#187#919966402076#Naveen hi 9966402076#N#NULL#N#NULL#NULL
17#187#919885900681#Chakri hi 9885900681#N#NULL#N#NULL#NULL
18#187#919963791113#Pols hi 9963791113#N#NULL#N#NULL#NULL



now my file have only

15#187#919985339980#Suneel hi 9985339980#N#NULL#N#NULL#NULL
16#187#919966402076#Naveen hi 9966402076#N#NULL#N#NULL#NULL
17#187#919885900681#Chakri hi 9885900681#N#NULL#N#NULL#NULL
18#187#919963791113#Pols hi 9963791113#N#NULL#N#NULL#NULL


i loss the


10#186#919985339980#hiii#N#NULL#N#NULL#NULL
11#186#919966402076#hiii#N#NULL#N#NULL#NULL
12#186#919885900681#hiii#N#NULL#N#NULL#NULL
13#186#919963791113#hiii#N#NULL#N#NULL#NULL
14#186#919989912348#hiii#N#NULL#N#NULL#NULL

these data


i want out put is.....................................


10#186#919985339980#hiii#N#NULL#N#NULL#NULL
11#186#919966402076#hiii#N#NULL#N#NULL#NULL
12#186#919885900681#hiii#N#NULL#N#NULL#NULL
13#186#919963791113#hiii#N#NULL#N#NULL#NULL
14#186#919989912348#hiii#N#NULL#N#NULL#NULL
15#187#919985339980#Suneel hi 9985339980#N#NULL#N#NULL#NULL
16#187#919966402076#Naveen hi 9966402076#N#NULL#N#NULL#NULL
17#187#919885900681#Chakri hi 9885900681#N#NULL#N#NULL#NULL
18#187#919963791113#Pols hi 9963791113#N#NULL#N#NULL#NULL



it is possible plz help me




yous
pols

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-05 : 15:03:17
Try to replace that -o with >>


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -