本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
/**==** 1. 自定義函數用于group by時出錯 **==**/--一個簡單的函數create function f_str(@str sysname,@i int)returns char(1)as begin  return(substring(@str,@i,1)) endgo
--下面是測試
--定義測試數據declare @t table(name sysname)insert into @t values('abcd')
--有group by的情況,結果錯誤select a=dbo.f_str(name,1),b=dbo.f_str(name,2)from @tgroup by dbo.f_str(name,1),dbo.f_str(name,2)
--無group by的情況,結果正確select a=dbo.f_str(name,1),b=dbo.f_str(name,2)from @tgo
--刪除測試的自定義函數drop function f_str
/*--測試結果a    b    ---- ---- a    a
(所影響的行數為 1 行)
a    b    ---- ---- a    b
(所影響的行數為 1 行)--*/