日期:2014-05-18 浏览次数:20847 次
public string getLog_No() { string strTemp=""; string sql="select * from (select nvl(log_no,'0') from equip_change_logic t order by log_id desc) where rownum<=1"; MyOraComm.ConnForOracle cfo=new MyOraComm.ConnForOracle("connstr"); cfo.OpenConn(); System.Data.OracleClient.OracleDataReader oraDataRead=cfo.ReturnDataReader(sql); if(oraDataRead.Read()) strTemp=oraDataRead[0].ToString(); else strTemp="0"; oraDataRead.Close(); cfo.CloseConn(); if(strTemp.Length==7) { string year,xuhao; year=strTemp.Substring(0,4); xuhao=strTemp.Substring(4,3); if(year==System.DateTime.Now.ToString("yyyy")) { strTemp=(int.Parse(strTemp)+1).ToString(); } else strTemp=System.DateTime.Now.ToString("yyyy")+"001"; } else { strTemp=System.DateTime.Now.ToString("yyyy")+"001"; } return strTemp; }
------解决方案--------------------
用纯粹的sql效率会比较高些。
create table #temp(
Id int identity(1,1),
DDateTime datetime
)
go
insert into #temp(DDateTime)
select '2010-1-1'
union all
select '2011-2-1'
union all
select '2012-1-1'
union all
select '2011-4-1'
union all
select '2010-1-1'
select *,datepart(year,DDateTime)*1000+id from #temp order by datepart(year,DDateTime)*1000+id asc