tarleaa
14 years agoContributor
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
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