create table ACTesting
(
id int identity(1,1),
item nvarchar(max) not null,
Issued nvarchar(max) null,
Used nvarchar(max) null,
Returned nvarchar(max) null,
Balance as(dbo.Issued(issued)),
Total_qty nvarchar(max)
)
alter function dbo.Issued(@issued nvarchar)
returns int
as
Begin
declare @Issued_Qty int = cast(@issued as int)
declare @Amount23 int
if not exists(select * from ACTesting)
begin
declare @Bal_Qty int=cast((Select Balance from
ACTesting where id =(select max(id) from
ACTesting)) AS int)
set @Amount23=@Bal_Qty-@issued
return @Amount23
End
else
declare @Total_Qty int=cast((Select Total_qty from
set @Amount23=@Total_Qty