locked
Convert T-SQL query to DB2 query RRS feed

  • Question

  • I am trying to convert a T-SQL query to DB2 (v.9.7) query but have no luck.

    I have tested following T-SQL query using query tool of SQL Server Management Studio and it works fine as expected.

    SELECT CASE WHEN (EXISTS (SELECT NULL FROM "CUSTOMERS" t0) ) THEN 1 ELSE 0 END AS "value"

    The query is originally from following C# code: 

    TestQuery(() => db.Customers.Any());

    I try to run the query using query tool of IBM Data Studio 4.1.0.1 Client and get error: SQLCODE=-104, SQLSTATE=42601, DRIVER=4.17.30

    How to convert it to DB2 correctly?

    Any help would be greatly appreciated! Thanks in advance.

    Magnus

    Friday, June 27, 2014 1:28 PM

Answers

All replies

  • First remove the double quotes, DB2 doesn't like them.

    Second, we need more information about what you're trying to achieve, and the objects you are using. What's the DLL for customer?

    Friday, June 27, 2014 1:35 PM
  • Best for you to post the question at a DB2 forum.

    Kalman Toth Database & OLAP Architect SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012








    • Proposed as answer by Fanny Liu Monday, June 30, 2014 3:11 PM
    • Marked as answer by Fanny Liu Monday, July 7, 2014 6:17 AM
    Friday, June 27, 2014 1:46 PM
  • So this is not the right place to ask about DB2. What I can say is that if you had been converting to Oracle, you would have needed to add "FROM dual" to your query.

    That is, on Oracle you cannot leave out the FROM clause, why they have this funky "dual". Whether you can leave out FROM on DB2, I have no idea, but I raise this is a potential problem.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Friday, June 27, 2014 2:15 PM