Save the Result Of a sql server express query to a text file from sql server express not from command prompt

  • No change the same error ......

    Access Denied

    Null

    Anujahnavi S.

  • No change the same error ......

    Access Denied

    Null

    Anujahnavi S.

  • Hi Anu,

    change the output path to "C:\Save.txt" and try it.

    FYI:

    ----

    Create Trigger TestTrigger1

    On dbo.tablefortrigger

    For Insert

    As

    Begin

    Set nocount on

    Declare @msg nvarchar(255) /*Check sp_addmessage */

    Declare @CmdString nvarchar (2000)

    set @msg = 'Inserted \ tablefortrigger \' + convert(varchar(20), getdate()) + ' — '

    +(select convert(varchar(5), track)

    + ',' + lastname + ', ' + firstname

    from inserted)

    RAISERROR(50006,10,1,@msg)

    Set @CmdString = 'echo ' + @msg + ' > C:\save.txt'-- changed.

    EXEC master..xp_cmdshell @CmdString

    Set nocount off

    End

    Go

  • Hi,

    try to save to c: drive

    Set @CmdString = 'echo ' + @msg + ' > C:\Documents and Settings\admin\Desktop\save.txt'

  • No Ahmed No change in the error.

    Access Denied

    NULL

    Don't think iam eating ur brain.

    Pleaseee......

    Anujahnavi S.

  • Did u check my post...

    Actually change the .txt file path to C:\Save.txt.

  • Hi,

    try to save to c: drive I meant Set @CmdString = 'echo ' + @msg + ' > C:\save.txt'

    I meant you dont have write to create file in C:\Documents and Settings\admin\Desktop

    Regards

  • yes Ahmed i placed it in d: drive.

    When i place the .txt file in c: i din't get but when i placed it in d:

    one row in the output was removed(i.e., Access denied) is rectified but ...........

    That second row is not yet..........

    Null is stinn there.

    Actual Result is

    1..........Inserted \ tablefortrigger \Nov 27 2007 11:33AM — 6,Nori, Prathi

    2..........(1 row(s) affected)

    but iam getting only

    1..........Inserted \ tablefortrigger \Nov 27 2007 11:33AM — 6,Nori, Prathi

    in my notepad.

    error is

    NULL

    Thanks alot Ahmed.

    Iam so happy

    thanks alot.

    Anujahnavi S

  • So Im happy for you just re-write EXEC master..xp_cmdshell @CmdString, no_output

    to not have the output null

    Regards,

    Ahmed

  • use ">> C:\Save.txt" instead of "> C:\Save.txt"

  • hi Ahmed,

    i got it Ahmed thanks alot...................

    Iam very very happy.

    u know actually even my team lead Din't get this .......... if u dont help me i too will not be getting thanks .........alooooooooooooooooooot

    Today party in my cabin for getting this tasks result to a text file.

    Thanks Ahmed.....Thanks alot Ahmed.

    Please help me in every aspect .i suppose u will .thanks alot thank uuuuuuuuu.

    Anujahanvi S.

  • Hi Ahmed,

    Y not responding?

    ok

    If iam hving doubt u will or what.

    My TeamLeader said

    "hmm Anu Did a Good Job".

    All this credit goes to u Ahmed.

    This is the first time i got help from a unknown person.Thanks alot.

    Will be waiting for ur mail Ahmed.

    Anujahnavi S.

  • hi Ahmed,

    Thanks alot

    My Team Leader Said

    "hmm Anu ,U did a Good Job"

    I felt happy it's because of u .

    Thinking that i dint give any reply back

    I was giving mail to the other person by thinking it's u .

    Now iam hving other question.

    Want to save the whole records in the table to the xml file.

    in xml file iam saving the result but whole records iam not getting.

    will be waiting for ur reply

    Anujahnavi S.

  • Hi anujahnavi,

    set nocount on

    EXEC master.dbo.xp_cmdshell 'bcp "select * from tablefortrigger order by track FOR XML Auto, ELEMENTS, root(''Tracks'')" queryout c:\Result.xml -S. -Uusername -Ppassword -c -r -t', no_output

    set nocount off

    Regards,

    Ahmed

  • hi Ahmed,

    Can u be a bit clear about this saving to xml file.

    What r those

    bcp,ELEMENTS,root,-c,-r,-t?

    and can the xml file be created when the trigger is fired in sql server express?

    In that file result must be placed .can we do this?

    Thanks & Regards

    Anujahnavi S.

Viewing 15 posts - 16 through 30 (of 55 total)

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