将VB条件转换为SQL条件

时间:2018-01-26 10:22:21

标签: sql vb.net

我需要在SQL查询中执行一些VB条件。这可能吗?这里是代码::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::

If (ds.Tables(0).Rows.Count > 0) Then

    Dim timeIn = ds.Tables(0).Rows(0)("TimeIn").ToString
    Dim timeOut = ds.Tables(0).Rows(0)("TimeOut").ToString


    If Not String.IsNullOrEmpty(timeIn) And Not String.IsNullOrEmpty(timeOut) Then

        Dim result = DateTime.Compare(Convert.ToDateTime(timeIn), Convert.ToDateTime(timeOut)) 
If result > 0 Then 'last timeIn later than last timeOut
            attendanceStatus = "On"
        Else
            attendanceStatus = "Off"
        End If

    ElseIf Not String.IsNullOrEmpty(timeIn) And String.IsNullOrEmpty(timeOut) Then

        attendanceStatus = "On"

        End If

        lblAttendStatus.Text = attendanceStatus

    End If

End If 

1 个答案:

答案 0 :(得分:1)

您可以通过在SELECT:

之后包含在SQL语句中来实现
CASE WHEN TimeIn < TimeOut THEN 'Off' ELSE 'On' END AS attendanceStatus,