存储过程有参数@aid,@bid,@cid等参数
DECLARE @Where varchar(1024)
if(@aid=0)
set @Where='bid='+@bid
else
set @Where='cid='+@cid
.....下面判断是否存在记录 IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and + @Where))
begin
update 数据
where @Where
end
else
begin
insert 数据
end这么写有语法错误,高手给指点一下吧
DECLARE @Where varchar(1024)
if(@aid=0)
set @Where='bid='+@bid
else
set @Where='cid='+@cid
.....下面判断是否存在记录 IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and + @Where))
begin
update 数据
where @Where
end
else
begin
insert 数据
end这么写有语法错误,高手给指点一下吧
IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and + @Where))
set @strAircomE =' AND [dbo].[IsExtisAir](AircomE,'''+@FlightNo+''',IsUse)=1 '
其次:IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and + @Where)) 不可以这样写,既然你用的是拼接sql语句的方式去执行sql,就要使用exec()或者exec sp_executesql @sqlstring 这种方式来执行你拼接的sql 。update 数据 where @Where ---同理
declare @sql varchar(max)
set @sql='
IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and '+ @Where+'))
begin
update 数据
where @Where
end
else
begin
insert 数据
end'
--print @sql
exec(@sql)
set @sql='
IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and '+ @Where+'))
begin
update 数据
where '+@Where +
'end
else
begin
insert 数据
end'
--print @sql
exec(@sql)
set @sql='
IF(EXISTS(SELECT 1 FROM table1 WHERE 1=1 and '+ @Where+'))
begin
update 数据
where '+@Where +
'end
else
begin
insert 数据
end'
--print @sql
exec(@sql)