輸入2012和2019 能找到BBB這筆資料
where 2012>=year(convert(datetime,substring([Year],1,2)+'/01'+SUBSTRING([Year],3,5)))
and 2019<=year(convert(datetime,SUBSTRING([Year],9,2)+'/01'+SUBSTRING([Year],11,5)))
輸入2013和2015 能找到BBB這筆資料
where 2013>=year(convert(datetime,substring([Year],1,2)+'/01'+SUBSTRING([Year],3,5)))
and 2015<=year(convert(datetime,SUBSTRING([Year],9,2)+'/01'+SUBSTRING([Year],11,5)))
輸入2015和2016 能同時找到AAA和BBB這兩筆資料
where 2015>=year(convert(datetime,substring([Year],1,2)+'/01'+SUBSTRING([Year],3,5)))
and 2016<=year(convert(datetime,SUBSTRING([Year],9,2)+'/01'+SUBSTRING([Year],11,5)))
更簡潔的語法
where 2012>=convert(int,SUBSTRING([Year],4,4))
and 2019<=convert(int,SUBSTRING([Year],12,4))
where 2013>=convert(int,SUBSTRING([Year],4,4))
and 2015<=convert(int,SUBSTRING([Year],12,4))
where 2015>=convert(int,SUBSTRING([Year],4,4))
and 2016<=convert(int,SUBSTRING([Year],12,4))
非常感謝您,我試試看!
抓後面年分 可以改用 RIGHT([Year],4) 也可以