2009-05-06 14 views
0

クエリは私にいくつかのエラーを与えます:ユーザ定義関数のパラメータも追加するには?

メッセージ156、レベル15、状態1、行4 'from'というキーワードの構文が正しくありません。 メッセージ156、レベル15、状態1、行9 'group'キーワードの構文が正しくありません。

select 
Count(Page) as VisitingCount, 
dbo.fn_GetActivityLogsArranger(CONVERT(VARCHAR(5),Date, 108)as [Time] 
from scr_SecuristLog  
where Date between '2009-04-30' and '2009-05-02'  
and [user] in(select USERNAME    
    from scr_CustomerAuthorities 
where customerID=Convert(varchar,4) and ID=Convert(varchar,43))  
group by CONVERT(VARCHAR(5),Date, 108) order by CONVERT(VARCHAR(5),Date, 108) asc 
------------------------------------------------------------------------------------------------------ 
create FUNCTION [dbo].[fn_GetActivityLogsArranger] 
(
@time AS nvarchar(max) 
) 

RETURNS nvarchar(max) 
AS 
BEGIN 
declare @Return varchar(30) 

select @Return = case 
when @time between '15:00' and '15:30' then '15:00-15:30' 
when @time between '15:30' and '16:00' then '15:30-16:00' 
when @time between '16:00' and '16:30' then '16:00-16:30' 
when @time between '16:00' and '16:30' then '16:00-16:30' 
when @time between '16:30' and '17:00' then '16:30-17:00' 
when @time between '17:00' and '17:30' then '17:00-17:30' 
when @time between '17:30' and '18:00' then '17:30-18:00' 
else 'Unknown' 
end 
Return @Return 
end 

答えて

2

かっこ

select 
Count(Page) as VisitingCount, 
dbo.fn_GetActivityLogsArranger(CONVERT(VARCHAR(5),Date, 108)**)** as [Time] 
from scr_SecuristLog  
where Date between '2009-04-30' and '2009-05-02'  
and [user] in(select USERNAME    
    from scr_CustomerAuthorities 
where customerID=Convert(varchar,4) and ID=Convert(varchar,43))  
group by CONVERT(VARCHAR(5),Date, 108) order by CONVERT(VARCHAR(5),Date, 108) asc 
+0

を逃したくさんありがとうございました。あなたは正しいです。別のquesを見てください.http://stackoverflow.com/questions/829089/how-to-call-user-defined-function-in-order-to-use-with-select-group-by-order-by – Penguen

関連する問題