Dim sCon As New SQLConnect
strSql = " select distinct DATEPART(yyyy,fl_date) as fl_date " & _
" from attendancemast" & _
" where 1 = 1" & _
" order by fl_date"
'" union " & _ commented
'" select year(GETDATE())" commented
sCon.sqlCmd.CommandText = strSql
sCon.sqlReader = sCon.sqlCmd.ExecuteReader
cboYear.Items.Clear()
cboYear.Items.Add(New ListItem("", ""))
While sCon.sqlReader.Read
cboYear.Items.Add(New ListItem(sCon.sqlReader("fl_date")))
End While
sCon.sqlReader.Close()
在这个SQL查询中,我从我的数据库中选择2004年到2013年,我希望通过union mehtod填写此查询中当前年份和明年的下拉列表
答案 0 :(得分:0)
我怀疑是否需要打开一个SQL连接来获取当前年份和明年,但这样做会。
SELECT YEAR(GetDate()) as fl_date
UNION SELECT YEAR(GetDate()) + 1