日期:2014-05-18 浏览次数:20719 次
Select top 5 vol_ArcType,vol_QZH,Vol_DH,Vol_AJBT,Vol_YS,Vol_BGQX,
(
case when charindex('-',Vol_Date)>0
then
case
when len( substring(Vol_Date,1,charindex('-',Vol_Date)-1))=4 then convert(datetime, substring(Vol_Date,1,charindex('-',Vol_Date)-1)+'.01.01',120)
when len( substring(Vol_Date,1,charindex('-',Vol_Date)-1))=7 then convert(datetime, substring(Vol_Date,1,charindex('-',Vol_Date)-1)+'.01',120)
else convert(datetime, substring(Vol_Date,1,charindex('-',Vol_Date)-1),120)
when charindex('-',Vol_Date) <1
then
case
when len(Vol_Date)=4 then convert(datetime,Vol_Date+'.01.01',120)
when len(Vol_Date)=7 then convert(datetime,Vol_Date+'.01',120)
else convert(datetime,Vol_Date,120)
end
) as Vol_BZQSRQ From Table
------解决方案--------------------
这样试试
Select top 5 vol_ArcType,vol_QZH,Vol_DH,Vol_AJBT,Vol_YS,Vol_BGQX,
( case
when (charindex('-',Vol_Date)>0) then
case
when len( substring(Vol_Date,1,charindex('-',Vol_Date)-1))=4 then convert(datetime, substring(Vol_Date,1,charindex('-',Vol_Date)-1)+'.01.01',120)
when len( substring(Vol_Date,1,charindex('-',Vol_Date)-1))=7 then convert(datetime, substring(Vol_Date,1,charindex('-',Vol_Date)-1)+'.01',120)
else convert(datetime, substring(Vol_Date,1,charindex('-',Vol_Date)-1),120)
end
when (charindex('-',Vol_Date) <1) then
case
when len(Vol_Date)=4 then convert(datetime,Vol_Date+'.01.01',120)
when len(Vol_Date)=7 then convert(datetime,Vol_Date+'.01',120)
else convert(datetime,Vol_Date,120)
end
end) as Vol_BZQSRQ From Table