create txt file

  • i have a select statement and through this select statement i want to create txt file .if is a possible give a better suggestion to me as soon as possible...thanks

  • pratyush.singh.chandra (11/19/2008)


    i have a select statement and through this select statement i want to create txt file .if is a possible give a better suggestion to me as soon as possible...thanks

    master..xp_cmdshell 'bcp master..sysobjects out c:\file.bcp -S -U -P -c '

    but the path would be relative to sql server

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • You could also use the sqlcmd command line utility for this - you can specify either a path on the server or use a UNC path (as long as access to the UNC path is available)

    sqlcmd -S -d master -E -Q "SELECT * FROM sys.objects" "C:\MasterObjects.txt"

    sqlcmd -S -d master -E -Q "SELECT * FROM sys.objects" \\UNCPath\MasterObjects.txt

    sqlcmd -S -d master -E -Q "sp_help [sys.objects]" C:\sysobjects.txt

    Lookup the sqlcmd syntax for details on all the options available

  • One more option is to use OSQL (from command line or from SQL Server with xp_cmdshell).

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • how to run this query in window authentication mode can any one give the suggestion

    EXEC master..xp_cmdshell 'bcp "SELECT * FROM persondb..[company]" queryout d:\mushi.txt"" -U sa -[b]P[/b] -c -t

  • how to run this query in window authentication mode can any one give the suggestion

    EXEC master..xp_cmdshell 'bcp "SELECT * FROM persondb..[company]" queryout d:\mushi.txt"" -U sa -P -c -t

  • pratyush.singh.chandra (11/19/2008)


    how to run this query in window authentication mode can any one give the suggestion

    EXEC master..xp_cmdshell 'bcp "SELECT * FROM persondb..[company]" queryout d:\mushi.txt"" -U sa -P -c -t

    Instead of using the -U and -P switches and supply the user and password, use the -T switch.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 7 posts - 1 through 6 (of 6 total)

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