connection with Sybase

  • Hello Friends,

    I have employee table which is in sybase, which looks like

    EmployeeIDEmpName Salary State

    1 John 3000 TX

    2 Robin 4000 NY

    3 Mitchelle 7000 CA

    4 Joe 8000 NY

    5 Jack 9000 FL

    6 Karen 2500 NY

    7 David 4500 CA

    If I run following 4 line in sql server, it gives output perfectly as above.

    declare @abc varchar(2000), @conn varchar(200)

    select @conn = ‘Driver={SYBASE ASE ODBC Driver};Srvr=xyz;Uid=newyork;Pwd=nycity;DB=advworld’

    SELECT @abc = 'select * from employee'

    EXEC('Select * FROM OPENROWSET(''MSDASQL'', ''' + @conn + ''', ''' + @abc + ''')')

    Instead of this query 'select * from employee'. I want following query to execute ‘Select * from employee where Salary > 3000 and State in(‘CA’,’NY’)’

    Because of lack of knowledge in using single quotation, I am having problem could you please help me?

  • Munabhai (7/2/2012)


    Hello Friends,

    I have employee table which is in sybase, which looks like

    EmployeeIDEmpName Salary State

    1 John 3000 TX

    2 Robin 4000 NY

    3 Mitchelle 7000 CA

    4 Joe 8000 NY

    5 Jack 9000 FL

    6 Karen 2500 NY

    7 David 4500 CA

    If I run following 4 line in sql server, it gives output perfectly as above.

    declare @abc varchar(2000), @conn varchar(200)

    select @conn = ‘Driver={SYBASE ASE ODBC Driver};Srvr=xyz;Uid=newyork;Pwd=nycity;DB=advworld’

    SELECT @abc = 'select * from employee'

    EXEC('Select * FROM OPENROWSET(''MSDASQL'', ''' + @dsn + ''', ''' + @sql + ''')')

    Instead of this query 'select * from employee'. I want following query to execute ‘Select * from employee where Salary > 3000 and State in(‘CA’,’NY’)’

    Because of lack of knowledge in using single quotation, I am having problem could you please help me?

    you would need to use a double ' ('') to escape the quotes so you dont loose the text string. so your select @abc would become

    SELECT @abc = 'Select * from employee where Salary > 3000 and State in(''CA'',''NY'')'

    the rest of the query would be the same. (except that you are using @sql and not @abc in your exec statement)


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • I did try that way but it still throwing an error.

  • what is the exact error you are getting. if you were getting no errors with the code you posted the changes to the code should not have caused any errors so it may be something else is going on.

    however only the exact error message will tell


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

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

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