SQL Serverに、次の値を持つStartDateフィールドを持つテーブルプロジェクトがあります。
15-02-2013 15:02:40
20-08-2011 10:11:20
2013 and 2011
など私は次のようなクエリで試しただけのように、明確な年の値を取得する必要があります
select (case when charindex(' ', StartDate) > 0
then left(StartDate, charindex(' ', (StartDate))-1)
else StartDate
end) as StartDate FROM [kneipp].[dbo].[kn_projects]
結果を次のように与えまし15-02-2013 and 20-08-2011
た
select (case when charindex('-', StartDate) > 0
then right(StartDate, charindex('-', reverse(StartDate))-1)
else StartDate
end) as lastone FROM [kneipp].[dbo].[kn_projects]
取得しました2013 15:02:40 and 2011 10:11:20
私の期待した結果を達成する方法