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
select link_id, sum(case NUM
when 1 then value
when 2 then value*(-1)
else 0
end)
from (select ROW_NUMBER() over (PARTITION BY link_id order by [date] desc) as NUM, link_id, value from log) t
group by link_id
/*
Входные параметры:
@DistrinctName - название района
@NewFIO - новые ФИО главы
таблица District например содержит поля название района и ФИО главы
Коды возврата процедуры:
0 -Штатное завершение (процедура отработала нормально)
-1000 - не указано (или пустое) название района
-1001 - не указано (или пустое) новое имя главы
-1002 - района с таким названием не существует
*/
create procedure dbo.upd_FIO
@DistrinctName varchar(150)
, @NewFIO varchar(1024)
as
begin
if isnull(@DistrictName, '') = ''
return -1000
if isnull(@NewFIO, '') = ''
return -1001
if not exists (select top 1 1 from District where DistrictName = @DistrictName)
return -1002
update District set FIO = @NewFIO
where DistrictName = @DistrictName
return 0
end