Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    india
    Posts
    67

    Unanswered: retrieve " using bcp-urgent

    hi gurus,
    how to get " using bcp
    e.g
    select '"'+name+'"' from sysobjects
    results
    "name"
    "name1"

    I want to get the same using bcp ,so that i can populate into a file
    something like

    set @cmd='BCP "select '"' +name +'"' ,uid from sysobjects" QUERYOUT "' + 'vrs.txt' + '" -w -T -S -t , '
    -- Executing the BCP Command
    EXEC MASTER..XP_CMDSHELL @Cmd

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    If [name] is the name of a column then you don't and probably shouldn't enclose it in singel quotes anyway. You may want to enclose it in brackets just in case the designer did not follow good naming conventions:

    set @cmd='BCP "select [' +name +'], uid....

    Can you post an example of what you want your final command string to look like?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    I thought this would work...but it doesn;t export the quoyes..(I'd still use brackets in either case)

    Code:
    DECLARE @cmd varchar(8000)
    set @cmd='BCP "select ' + '''' + CHAR(34)+ '''' + '+' + 'name' + '+' + '''' + CHAR(34) + '''' 
    	+ ' ,uid from sysobjects" QUERYOUT "' + 'C:\vrs.txt' 
    	+ '" -w -T -S -t"," ' 
    -- Executing the BCP Command
    SELECT @cmd
    
    EXEC MASTER..XP_CMDSHELL @Cmd
    
    EXEC MASTER..XP_CMDSHELL 'DIR C:\*.txt'
    
    EXEC MASTER..XP_CMDSHELL 'COPY C:\*.txt D:\Tax\*.*'
    GO
    
    CREATE VIEW myView99 AS
    SELECT '"'+name+'"' AS myName99, uid FROM sysobjects
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Using a view works though....(I'd still use brackets)

    Code:
    USE Northwind
    GO
    
    CREATE VIEW myView99 AS
    SELECT '"'+name+'"' AS myName99, uid FROM sysobjects
    GO
    
    DECLARE @cmd varchar(8000)
    SET @cmd = 'bcp Northwind.dbo.myView99 OUT C:\myView99.txt -w -T -S -t","'
    
    EXEC MASTER..XP_CMDSHELL @Cmd
    
    EXEC MASTER..XP_CMDSHELL 'DIR C:\*.txt'
    
    EXEC MASTER..XP_CMDSHELL 'COPY C:\*.txt D:\Tax\*.*'
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •