Question

I have one query that returns a single element.

This record has a empty data (Length = 0, but not null).

I Want to know if is possible force the query return EOF if the data length equals zero.

sql="select Code from AS_Table where NumAtend = 1234 "
set rs = Con1.execute(sql)

if not rs.eof then
    Json("status") = true
else
    Json("status") = false
end if

I Know you can test it after the "IF", but don't want to know how to fix that (Because I already know).

My question is "if" it is possible force an EOF if the len(Code)=0

Was it helpful?

Solution

I added a comment earlier but seen as though everyone has jumped on the answer wagon here goes;

SELECT Code FROM AS_Table WHERE NumAtend = 1234 AND LEN(Code) > 0

By adding the LEN(Code) > 0 will cause only results with Code with a length greater then 0 to be returned.

In each instance you want a ADODB.Recordset to be returned or you will not be able to check the Recordset.EOF property this is because the ADODB.Recordset will have a Recordset.State of adStateClosed and any attempt to access it's properties will return an error (adErrObjectClosed).

 Error No.   | Description
------------------------------------------------------------------
-2146824578  | Operation is not allowed when the object is closed.

What about using RETURN?

The problem with RETURN is you will not get a resultset back so the ADODB.Recordset will be in the state adStateClosed and the same as above will apply.


Useful Links

OTHER TIPS

You can't force ADO to change its defined behaviour (unless you patch the .dll). Either add an If clause/statement to your code or a WHERE clause ("... WHERE codelength > 0") to your SQL statement.

To do this programatically through your application, you could filter your result set.

sql="select Code from AS_Table where NumAtend = 1234 "
set rs = Con1.execute(sql)
rs.filter = "status <> ''"

if not rs.eof then
    Json("status") = true
else
    Json("status") = false
end if

This will give you rs.EOF if the "status" field is empty

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top