Forum Discussion

tarleaa's avatar
tarleaa
Contributor
14 years ago

DB Query

Hello,



I have the following function that connects to the DB and runs a query that should return a single user name. The problem is that the query works in SQL but does not return a value when ran in TC.

If I simplify the query it returns a value. Is there a length limitation (like 256 characters) or any kind of limitation for a query?



Here is the function:



function getUsername()

{

    var qry = ADO.CreateADOQuery();



    qry.ConnectionString = "Driver={SQL Native Client};Server=xxx;" +         //connect to the DB

                        "Database=xxx;Uid=xxx;Pwd=xxx";

                        

    qry.SQL = "select top 1 u.email from users u (nolock) inner join userpersonas up (nolock) on up.userid = u.id outer apply (select id from userpersonas (nolock) where userid = u.id and personaid > 1) op where up.personaid = 1 and up.personatypeid = 1 and up.personastatusid = 1 and op.id is null";



  qry.Open();

  var user = qry.FieldByName("email").AsString;                           // store the user name in variable

  Log.Message(user);

  qry.Close();

}




Thanks,

Andrei

3 Replies


  • Hello Andrei,





    TestComplete doesn't execute SQL queries itself. Instead, it passes the query to the ADO provider, which you specified in the connection string. So, please verify that the database provider can process your SQL query correctly.
  • Hello Alex,



    it looks like it didn't like that I was using "outer apply" in the query.

  • Hello Andrei,





    Indeed, SQL providers issued before SQL 2005 don't support the CROSS and OUTER APPLY operators. To be able to use these keywords, you need to connect to the database using a newer version of the SQL provider that supports SQL 2005 syntax.