CREATE FUNCTION FC_LIST ( @list_type nvarchar(10), @uid bigint, @start_number smallint, @end_number smallint )
RETURNS TABLE
AS
BEGIN
DECLARE @type nvarchar(10)
DECLARE @user_type nvarchar(25)
BEGIN
SET @user_type = "aa"
END
IF @list_type = "a"
BEGIN
SET @type = "a"
END
ELSE IF @list_type = "b"
BEGIN
SET @type = "b"
SET @user_type = "bb"
END
ELSE IF @list_type = "c"
BEGIN
SET @type = "c"
END
ELSE IF @list_type = "d"
BEGIN
SET @type = "d"
END
END
SELECT * FROM
(
SELECT ee, ff
FROM table
WHERE type = @type
IF @list_type = "a"
AND ( ee= '@uid' OR ff = '@uid')
ELSE
AND @user_type = '@uid'
END
GROUP BY ee, ff ) a
WHERE row_number between @start_number and @end_number
ORDER BY a.ee DESC END GO
위처럼 function만들 때 뭐가 잘못됐는지 계속 에러가 납니다..
에러메세지는.(빨강으로 표시한 부분)
키워드 'BEGIN' 근처의 구문이 잘못되었습니다.
키워드 'END' 근처의 구문이 잘못되었습니다.
IF 문 근처의 구문이 잘못되었습니다.
아시는 분 도와주세요 ㅠㅠㅠ |