Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse IIF in a SQL SELECT statement to display a warning if a value is too low
DescriptionThis example shows how to use IIF in a SQL SELECT statement to display a warning if a value is too low in Visual Basic 6.
KeywordsIIF, SQL, SELECT, database, warning
CategoriesDatabase
 
IIF takes three arguments: a Boolean expression to evaluate, the result that should be returned if the expression is True, and the result that should be returned if the expression is False. This example uses IIF to display the string WARNING if a test score value is less than 75 or an empty string if the score is not less than 75.
 
Private Sub Form_Load()
Dim warning_query As String
Dim query As String
Dim db_name As String

    warning_query = "IIF(Score<75, 'WARNING', '') AS " & _
        "Warning "
    query = "SELECT FirstName, LastName, TestNumber, Score, " & _
        "" & _
        warning_query & _
        "FROM Students, TestScores " & _
        "WHERE Students.StudentId = TestScores.StudentId " _
            & _
        "ORDER BY FirstName, LastName, TestNumber"

    db_name = App.Path
    If Right$(db_name, 1) <> "\" Then db_name = db_name & _
        "\"
    Data1.DatabaseName = db_name & "StudentData.mdb"
    Data1.RecordSource = query
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated