Considering that Grade.firstExam, Grade.secondExam, and Grade.finalExam are all TEXT and not numbers, i can't get the exact solution to convert null values into Zeros. I already tried to use NZ() but it returns an error message (Undefined Function 'NZ' in expression) im using VB.net with MS Access as my database. i also imported System.Data.OleDb Namespace.
SQLStatement = " SELECT Student.idNumber as 'IDno', "
SQLStatement &= " Student.lastName + ', ' + Student.firstName as 'FullName', "
SQLStatement &= " Grade.firstExam as 'firstExam', "
SQLStatement &= " Grade.secondExam as 'secondExam', "
SQLStatement &= " Grade.finalExam as 'finalExam', "
SQLStatement &= " ((CDBL(Grade.firstExam) + CDBL(Grade.secondExam) + CDBL(Grade.finalExam) + CDBL(Grade.finalExam)) / 4) as 'Average' "
sqlstatement &= "FROM Student LEFT OUTER JOIN Grade ON "
sqlstatement &= " Student.idNumber = Grade.idNumber "
sqlstatement &= "WHERE Student.idNumber = '" & StudentID & "' "
SQLStatement &= "ORDER BY ((CDBL(Grade.firstExam) + CDBL(Grade.secondExam) + CDBL(Grade.finalExam) + CDBL(Grade.finalExam)) / 4) DESC"
How can i convert empty string or null that exist in the field?
In your SQL try something like this:
SQLStatement &= " IIf(IsNull(Grade.firstExam),'0',Grade.firstExam) as 'firstExam', "
You are getting this message error probably because you are using the VB function from inside the SQL request:
mySQLRequest = "SELECT ..., NZ(yourNumber,0), ..."
the NZ function is not understood by the database engine
You should write down your request this way:
mySQLRequest = "SELECT ..., IIf([myField] Is Null,0,[myField]) as myField, ..."
来源:https://stackoverflow.com/questions/4705738/convert-null-to-zero-in-access-database