0

SQL查詢 開始日期和結束日期在同一個欄位的語法

froce iT邦大師 1 級 ‧ 2018-03-13 16:21:14 檢舉

allenlwh iT邦研究生 1 級 ‧ 2018-03-13 16:49:03 檢舉

wei225890 iT邦新手 5 級 ‧ 2018-03-13 16:51:30 檢舉

1 個回答

2
allenlwh
iT邦研究生 1 級 ‧ 2018-03-13 16:40:06

``````  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)))
``````

``````  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)))
``````

``````  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)))
``````
allenlwh iT邦研究生 1 級 ‧ 2018-03-13 16:44:12 檢舉

``````  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))
``````
wei225890 iT邦新手 5 級 ‧ 2018-03-13 16:52:00 檢舉