Syntax for Openquery

  • Hi all,

    Would you please show me the correct syntax to run a query from open query if I only know the ip address.  I entered something like this:

    select * from openquery(172.24.2.5,'select * from mytable where date >="4/1/05" and date <"4/2/05

    it gave me error."Server: Msg 170, Level 15, State 1, Line 1

    Line 1: Incorrect syntax near '172.24'."

    Thanks.

     

    Minh Vu

  • OPENQUERY requires that you create a linked server. You cannot specify an IP address.

    If you wish to use an IP address, try something like

    select * from OPENROWSET ( 'SQLOLEdB'

    , '172.24.2.5' ; 'username' ; 'password'

    ,'select * from mytable where date >="4/1/05" and date <"4/2/05"'

    )

  • Yes, you can. I just figured out. I needed to put my ip in bracket:

    [172.2.24.5].  It worked for me.

    Thanks,

    Minh

  • No, I am not getting it, the following error is raised

    'could not find server  '10.1.121.77' in sysservers. Execute sp_addlinkedserver to add the server to syservers'

  • Yes, you need to link the server before you can use open query.

    Minh

Viewing 5 posts - 1 through 4 (of 4 total)

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