declare @diff int
, @count int
select @diff = cash - @price
from users
where id = @uid
select @count = count
from shop
where item = @item
if (@count>0) and (@diff > 0)
begin
begin transaction
update users
set cash=cash-@price
where id=@uid
if exists (select top 1 from items where uid = @uid and item=@item)
update items
set count=count+1
where uid=@uid and item=@item;
else
insert into items
select @uid, @item, 1;
update shop
set count=count-1
where item=@item;
if @@error != 0
rollback
commit
end
create procedure [dbo].[WO_GNAGetBalance]
@in_CustomerID int
, @balance money output
, @result_code int output
, @result_msg varchar(255) output
as
begin
set nocount on
if not exists (select top 1 * from LoginID where CustomerID = @in_CustomerID)
begin
select @result_code = 6
, @result_msg = 'no CustomerID'
return 6
end
select @balance = sum(isnull(GamePoints, 0)) as GNABalance from LoginID
where CustomerID = @in_CustomerID;
if @@error != 0
begin
select @result_code = 7
, @result_msg = 'Error get balance'
return 7
end
select @result_code = 0
, @result_msg = 'Success!'
return 0
end
select name from table
where sum(param1+param2+param3)>5 as s
and ref_id = 'id данного человека'
order by s desc