Export Data in Text File Using SQLCMD in SQL SERVER 2005

  • 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

  • This was already addressed here:

    http://www.sqlservercentral.com/Forums/Topic734169-149-1.aspx

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

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