//我的代码应该是这样的
CREATE PROCEDURE REGISTRATION
@USERNAME VARCHAR(20)
AS
BEGIN
BEGIN IF
SELECT USERNAME FROM USERS WHERE USERNAME = @USERNAME
PRINT 'USER ALREADY EXITS'
ELSE
IF @USERNAME = 'NULL'
PRINT 'Fill username'
end
end
答案 0 :(得分:0)
试试这个:
CREATE PROCEDURE REGISTRATION
@USERNAME VARCHAR(20)
AS
BEGIN
declare @count as int
select @count = COUNT(*) from USER where USERNAME =@USERNAME
if(@count > 0)
print 'USER ALREADY EXITS' -- Record Exists
else
print 'Fill username' -- NULL
end
答案 1 :(得分:0)
使用存在。此外,格式被忽略并且很重要
CREATE PROCEDURE REGISTRATION
@USERNAME VARCHAR(20)=''
AS
BEGIN
IF exists(SELECT 1 FROM USERS WHERE USERNAME = @USERNAME)
begin
PRINT 'USER ALREADY EXITS'
end
ELSE
begin
PRINT 'Fill username'
end
end