select top 1000 id,username,usercode,isnull (dCompDt,convert(smalldatetime,'2078-06-06')) as newCompDt from tablename order by get_newCompDt desc
==========================
dCompDt是完成時間,已完成的(有時間)排在後面用倒序排,沒完成的排在前面(都是null值),
用上面的newCompDt方式來排好慢啊,運行要8秒左右,數據有30萬條記錄,已經top 1000了啊。
請問可以改成什麼樣的寫法會更快?
==========================
dCompDt是完成時間,已完成的(有時間)排在後面用倒序排,沒完成的排在前面(都是null值),
用上面的newCompDt方式來排好慢啊,運行要8秒左右,數據有30萬條記錄,已經top 1000了啊。
請問可以改成什麼樣的寫法會更快?
上面寫錯名稱應該是order by newCompDt desc
from tablename
order by case when dCompDt=null then 0 else 1 end,dCompDt desc
case when dCompDt is null then 0 else 1 end ,dCompDt desc
用=號會出錯,改成order by case when dCompDt is null then 0 else 1 end,dCompDt desc 後速度沒有改善啊。
select top 1000 id,username,usercode,isnull (dCompDt,convert(smalldatetime,'2078-06-06')) as newCompDt from tablename
case when dCompDt is null then 0 else 1 end,dCompDt desc
我的sql是寫在網頁裡的,數據庫我動不了