Citação Originally Posted by louis Ver Post
This query search all itens in all accounts...but no count.

Código:
DECLARE
@acid varchar(10),
@name varchar(10),
@inv_data binary(3792),
@ware_data binary(3840),
@type binary(1),
@group binary(1),
@grupo int,
@item int,
@count int


-- Coloque o grupo e número do item que deseja procura
set @grupo    = 0;
set @item    = 1;


print '-------------------------';
print 'ENCONTRADO NO INVENTORIO:';
print '-------------------------';


DECLARE LISTA CURSOR LOCAL FOR
SELECT inventory, name, AccountID FROM Character
OPEN LISTA
FETCH NEXT FROM LISTA INTO @inv_data, @name, @acid
WHILE @@FETCH_STATUS = 0
BEGIN


SET @count=0


WHILE @count<237 AND @inv_data IS NOT NULL
BEGIN
SET @type    =SUBSTRING(@inv_data,@count*16+1,2)
SET @group    =SUBSTRING(@inv_data,@count*16+10,2)


IF (@type = (SELECT CONVERT(varbinary(1), @item)) AND @group = (SELECT CONVERT(varbinary(1), (@grupo*16))))
  BEGIN
    print 'Conta: ' + @acid + ' Personagem: ' +  @name;
    SET @count=237;
  END


SET @count=@count+1


END


FETCH NEXT FROM LISTA INTO @inv_data, @name, @acid
END
CLOSE LISTA
DEALLOCATE LISTA


print '------------------';
print 'ENCONTRADO NO BAU:';
print '------------------';


DECLARE LISTA CURSOR LOCAL FOR
SELECT items, AccountID FROM warehouse
OPEN LISTA
FETCH NEXT FROM LISTA INTO @ware_data, @acid
WHILE @@FETCH_STATUS = 0
BEGIN


SET @count=0


WHILE @count<240 AND @ware_data IS NOT NULL
BEGIN
SET @type    =SUBSTRING(@ware_data,@count*16+1,2)
SET @group    =SUBSTRING(@ware_data,@count*16+10,2)


IF (@type = (SELECT CONVERT(varbinary(1), @item)) AND @group = (SELECT CONVERT(varbinary(1), (@grupo*16))))
  BEGIN
    print 'Conta: ' + @acid;
    SET @count=240;
  END


SET @count=@count+1


END


FETCH NEXT FROM LISTA INTO @ware_data, @acid
END
CLOSE LISTA
DEALLOCATE LISTA
This code only give accounts id and name character . but it not count total they have in their inventory and warehouse . Can you recode it can count all total ? from inventory and warehouse ?