我有两个表tbl_item
,tbl_category
现在我要做的就是仅在没有所选类别的记录时删除所选内容category
。如果删除存储过程应返回其他内容。请帮助。tbl_catetgory
tbl_item
category
1
0
ALTER PROCEDURE [dbo].[Sp_DelItemcategory]
@code int
AS
BEGIN
declare @sql varchar(max)
DECLARE @data VARCHAR(50)
set @sql='SELECT Cat_code FROM dbo.Tbl_ItemMaster WHERE Cat_code = '+@code;
declare dB_cursor cursor for
SELECT Cat_code FROM dbo.Tbl_ItemMaster WHERE Cat_code = @code
open dB_cursor
fetch next from dB_cursor into @data
WHILE @@FETCH_STATUS = 0
BEGIN
set @sql='delete from Tbl_ItemCategory where Cat_code='+@code;
exec @sql
FETCH NEXT FROM db_cursor INTO @data
END
CLOSE db_cursor
DEALLOCATE db_cursor
END