存储过程 存储变量 在线等!!谢谢!!!
create procedure CAD_add_component_layer
(
@layer_id int,
@com varchar(50)=null,
@layer varchar(50)=null
)
as
BEGIN TRANSACTION
declare @component_id int
declare @s varchar(100)
begin
set @s= 'select component_id from ph_component where component_name=( '+@com+ ') '
exec(@s)
end
begin
insert into ph_layer values(@layer_id,@component_id,@layer)
end
IF @@ERROR > 0 --OR @@ROWCOUNT = 0
BEGIN
RAISERROR( 'insert of comlayer failed ',16,1)
ROLLBACK TRANSACTION
RETURN @@ERROR
END
COMMIT TRANSACTION
RETURN 0
我想 查询出来的component_id值 在下面的insert语名用上!!! component_id该如何存储?????谢谢!!!
[解决办法]
set @s= 'select component_id from ph_component where component_name=( '+@com+ ') '
exec(@s)
你能不能不要这样搞啊,改成这样呢?
直接这样:
select @component_id=component_id from ph_component where component_name=@com