How to replace existing text file in sql server 2005

  • Hi All,

    i am execute the command

    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

    it get the output

    once agani i run the

    same command

    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 am get anothe output

    How to replace these two outputs at a one text file

    it is possible

    plase help meeeee........................

  • If I understand the question, then why don't you execute both queries with a UNION between them?

    CEWII

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

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