我在創建自己的函數時遇到了問題。我得到一個錯誤#1064 - 錯誤的語法在第10行(與'創建函數'一行),我無法弄清楚我做錯了什麼?SQL函數錯誤:1064
create table students (
id int primary key,
name varchar(30),
surname varchar(30),
class char(4),
born datetime,
grade varchar(10)
)
create function returnGrade
(@class char(4))
return varchar(10)
AS
BEGIN
declare @return varcahr(10)
@class = SUBSTRING(@class, 2, 1)
SELECT @return = CASE @class
WHEN '1' then 'first'
WHEN '2' then 'second'
WHEN '3' then 'third'
WHEN '4' then 'fourth'
ELSE 'unknown'
END
return @return
END
PS變量類看起來是這樣的: 'T3.A', 'T4.A', 'T4.B' 等
嘗試在create table和create function之間添加一個'GO'。另外,'declare @return varcahr(10)'應該是'varchar(10)' – 2012-04-19 00:25:10
以及..我添加了GO並且它寫道「你有一個1064 err在線#9附近'go create function returnGrade .. 。「 – SukiCZ 2012-04-19 00:29:24