代码之家  ›  专栏  ›  技术社区  ›  Candy083

SQL:靠近“)”的语法不正确,不能在时间范围内保存数据

  •  -2
  • Candy083  · 技术社区  · 6 年前

    添加此查询时出错:

    OR (CONVERT(VARCHAR(8),CAST('" & start.SelectedValue & "' AS DATETIME),108) <=  CONVERT(VARCHAR(8), [Time-in], 108) AND CONVERT(VARCHAR(8),CAST('" & ends.SelectedValue & "' AS DATETIME), 108)  >=   CONVERT(VARCHAR(8), [Time-out], 108) 
    

    这是整个查询:

     Dim SQL5 = New SqlCommand("SELECT Room, CONVERT(VARCHAR(8), [Time-in], 108) AS [Time-in], CONVERT(VARCHAR(8), [Time-out], 108) as [Time-out] FROM [RS].[dbo].[Time] WHERE CAST([Reserve_date] AS DATE) = CAST('" & Calendar1.SelectedDate.ToString("yyyy-MM-dd") & "' AS DATE) AND Room = ('" & roomType.SelectedValue & "' )                          AND (CONVERT(VARCHAR(8),CAST('" & start.SelectedValue & "' AS DATETIME),108) BETWEEN CONVERT(VARCHAR(8), [Time-in], 108) AND CONVERT(VARCHAR(8), [Time-out], 108)                                                                                                       OR (CONVERT(VARCHAR(8),CAST('" & start.SelectedValue & "' AS DATETIME),108) <=  CONVERT(VARCHAR(8), [Time-in], 108) AND CONVERT(VARCHAR(8),CAST('" & ends.SelectedValue & "' AS DATETIME), 108)  >=   CONVERT(VARCHAR(8), [Time-out], 108)                                                                                                                                                              OR CONVERT(VARCHAR(8),CAST('" & ends.SelectedValue & "' AS DATETIME), 108) BETWEEN CONVERT(VARCHAR(8), [Time-in], 108) AND CONVERT(VARCHAR(8), [Time-out], 108))", connection)
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Jayasurya Satheesh    6 年前

    你在结尾缺少a)

    OR (CONVERT(VARCHAR(8), CAST('" & start.SelectedValue & "' AS DATETIME), 108) <= CONVERT(VARCHAR(8), [Time-in], 108)
              AND CONVERT(VARCHAR(8), CAST('" & ends.SelectedValue & "' AS DATETIME), 108) >= CONVERT(VARCHAR(8), [Time-out], 108)
    );--Add one more ) Here