Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2003
    Location
    Frisco, TX
    Posts
    21

    Unhappy Unanswered: Syntax driving me bonkers.

    It checks just fine, but when I execute it I get a Line 1: Incorrect syntax near 'oC:'

    Here is what I have


    DECLARE @StartTime datetime
    DECLARE @path varchar(100)
    DECLARE @charDate varchar(25)
    DECLARE @part1 varchar(150)
    DECLARE @outText varchar(250)

    Select @StartTime = GetDate()

    set @path = '-o"C:\Test.txt" -w2000'
    set @charDate = CONVERT(varchar(30), @StartTime)

    set @part1 = 'osql -U "testConnector" -P "testConnector" -Q"select * from SlowResponses WHERE SlowResponses.SendTime > '
    set @outText = @part1 + '''' + @charDate + '''' + ' ' + @path

    print @outText

    exec master..xp_cmdshell @outText


    The print out looks like this:

    osql -U "testConnector" -P "testConnector" -Q"select * from SlowResponses WHERE SlowResponses.SendTime > 'Oct 22 2003 1:55PM' -o"C:\Test.txt" -w2000


    To me, this seems correct.

    Note that if I use the same code without the WHERE clause it does work just fine! In other words, if it looks like this:

    set @outText = 'osql -U "testConnector" -P "testConnector" -Q"select * from SlowResponses" -o"C:\Test.txt" -w2000'


    Can anyone please tell me what it is I am doing wrong? I've been trying everything I can thnk of for an hour now.

  2. #2
    Join Date
    Sep 2003
    Location
    KY
    Posts
    146

    Hi

    Probably because you are using single quote for date in Where clause . Change it to Double Quote and let us know ..

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322

    Re: Hi

    Originally posted by aashu
    Probably because you are using single quote for date in Where clause . Change it to Double Quote and let us know ..

    ahhh....no

    And how does it work if you don't supply the server name?

    (btw, thanks for the password...better edit it out)
    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
    Oct 2003
    Location
    Frisco, TX
    Posts
    21

    Re: Hi

    Originally posted by Brett Kaiser
    ahhh....no

    And how does it work if you don't supply the server name?

    (btw, thanks for the password...better edit it out)
    That is a test password... ("testConnection").

    The real password is...********* !)

  5. #5
    Join Date
    Sep 2003
    Location
    KY
    Posts
    146

    Talking Or

    Great ! Why did you tell us the actual pwd
    Last edited by aashu; 10-22-03 at 17:12.

  6. #6
    Join Date
    Oct 2003
    Location
    Frisco, TX
    Posts
    21

    Re: Hi

    Originally posted by aashu
    Probably because you are using single quote for date in Where clause . Change it to Double Quote and let us know ..
    I needed to add a double quote to what I had right before the -o "C:\

    That did it.

    Thanks.

  7. #7
    Join Date
    Oct 2003
    Location
    NH
    Posts
    3
    As you posted it, it didn't error on my system at all . . . of course the connection failed . . .

Posting Permissions

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