)AS begin if(@height>150 and @height<280) if(@weight>130 and @weight<200) if exists(select name from t_team where name=@team_name) begin insert into t_player values(@id ,@name,@sex,@birthday,@height,@weight,@team_name,@clothnumber,@hobby) return end end execute sp_player2 [@id='3003'], [@name='p3'], [@sex='m'], [@birthday='1982-2-13'], [@height=176], [@weight=150], [@team_name='t3'], [@clothnumber=8], [@hobby='games']
)AS -- begin --删除 if(@height>150 and @height<280) begin --添加 if(@weight>130 and @weight<200) begin --添加 if exists(select name from t_team where name=@team_name) begin insert into t_player values(@id ,@name,@sex,@birthday,@height,@weight,@team_name,@clothnumber,@hobby) return end end --添加 end --添加 -- end 删除
)AS if(@height>150 and @height<280) begin if(@weight>130 and @weight<200) begin if exists(select name from t_team where name=@team_name) begin insert into t_player values(@id ,@name,@sex,@birthday,@height,@weight,@team_name,@clothnumber,@hobby) return end end end 运行结果如下: execute sp_player2 @id='3003' @name='p3' @sex='m' @birthday='1982-2-13' @height='176' @weight='150' @team_name='t3' @clothnumber='8' @hobby='games' with RECOMPILE 运行结果如下: 服务器: 消息 170,级别 15,状态 1,行 3 第 3 行: '@name' 附近有语法错误。
create procedure sp_player2
(
@id varchar(10),
@name varchar(20),
@sex varchar(6),
@birthday datetime,
@height numeric(10),
@weight numeric(10),
@team_name varchar(20),
@clothnumber numeric(10),
@hobby varchar(20)
)AS
begin
if(@height>150 and @height<280)
if(@weight>130 and @weight<200)
if exists(select name
from t_team
where name=@team_name)
begin
insert into t_player
values(@id ,@name,@sex,@birthday,@height,@weight,@team_name,@clothnumber,@hobby)
return
end
end
execute sp_player2
[@id='3003'],
[@name='p3'],
[@sex='m'],
[@birthday='1982-2-13'],
[@height=176],
[@weight=150],
[@team_name='t3'],
[@clothnumber=8],
[@hobby='games']
(
@id varchar(10),
@name varchar(20),
@sex varchar(6),
@birthday datetime,
@height numeric(10),
@weight numeric(10),
@team_name varchar(20),
@clothnumber numeric(10),
@hobby varchar(20)
)AS
-- begin --删除
if(@height>150 and @height<280)
begin --添加
if(@weight>130 and @weight<200)
begin --添加
if exists(select name
from t_team
where name=@team_name)
begin
insert into t_player
values(@id ,@name,@sex,@birthday,@height,@weight,@team_name,@clothnumber,@hobby)
return
end
end --添加
end --添加
-- end 删除
用你的@name='p3' @id='3003' @sex='m'
得到的错误提示为:
服务器: 消息 170,级别 15,状态 1,行 3
第 3 行: '@id' 附近有语法错误。
fanmb(随便聊聊)兄弟
我用你的语句改写了一次:
create procedure sp_player2
(
@id varchar(10),
@name varchar(20),
@sex varchar(6),
@birthday datetime,
@height numeric(10),
@weight numeric(10),
@team_name varchar(20),
@clothnumber numeric(10),
@hobby varchar(20)
)AS
if(@height>150 and @height<280)
begin
if(@weight>130 and @weight<200)
begin
if exists(select name
from t_team
where name=@team_name)
begin
insert into t_player
values(@id ,@name,@sex,@birthday,@height,@weight,@team_name,@clothnumber,@hobby)
return
end
end
end
运行结果如下:
execute sp_player2
@id='3003'
@name='p3'
@sex='m'
@birthday='1982-2-13'
@height='176'
@weight='150'
@team_name='t3'
@clothnumber='8'
@hobby='games'
with RECOMPILE
运行结果如下:
服务器: 消息 170,级别 15,状态 1,行 3
第 3 行: '@name' 附近有语法错误。