CREATE TABLE /*!32312 IF NOT EXISTS*/ `mi_itens_nfiscal` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `tipo_nota` int(10) unsigned DEFAULT '1', `idNota` int(10) unsigned DEFAULT NULL, `codigo` char(60) DEFAULT NULL, `ref` char(60) DEFAULT NULL, `descricao` char(120) DEFAULT NULL, `ean` char(14) DEFAULT NULL, `ncm` char(8) DEFAULT NULL, `ex_tipi` char(3) DEFAULT NULL, `cfop` char(4) DEFAULT NULL, `genero` char(2) DEFAULT NULL, `u_comercial` char(6) DEFAULT NULL, `q_comercial` float unsigned DEFAULT '0', `v_comercial` float unsigned DEFAULT '0', `u_tributavel` char(6) DEFAULT NULL, `q_tributavel` float unsigned DEFAULT '0', `v_tributavel` float unsigned DEFAULT '0', `ean_tributavel` char(14) DEFAULT NULL, `total_frete` float unsigned DEFAULT '0', `total_seguro` float unsigned DEFAULT '0', `desconto` float unsigned DEFAULT '0', `valor_total_bruto` float unsigned DEFAULT '0', `st` char(3) DEFAULT NULL, `origem` int(1) unsigned DEFAULT NULL, `modBC` int(1) unsigned DEFAULT NULL, `vBC` float unsigned DEFAULT '0', `pRedBC` float unsigned DEFAULT '0', `pICMS` float unsigned DEFAULT '0', `vICMS` float unsigned DEFAULT '0', `modBCST` int(1) unsigned DEFAULT NULL, `pMVAST` float unsigned DEFAULT '0', `pRedBCST` float unsigned DEFAULT '0', `vBCST` float unsigned DEFAULT '0', `pICMSST` float unsigned DEFAULT '0', `vICMSST` float unsigned DEFAULT '0', `pIPI` float unsigned DEFAULT '0', `vIPI` float unsigned DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=14388 DEFAULT CHARSET=latin1; CREATE TABLE /*!32312 IF NOT EXISTS*/ `mi_produtos` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_fornecedor` int(10) unsigned DEFAULT NULL, `ref` varchar(50) DEFAULT NULL, `nome` varchar(100) DEFAULT NULL, `nome_fiscal` varchar(100) DEFAULT NULL, `descricao` longtext, `imagem` varchar(100) DEFAULT NULL, `codigo` varchar(50) DEFAULT NULL, `familia` varchar(100) DEFAULT NULL, `grupo` char(250) DEFAULT NULL, `cor` varchar(50) DEFAULT NULL, `tamanho` varchar(50) DEFAULT NULL, `fabricante` varchar(100) DEFAULT NULL, `tipo_cod_barra` char(1) DEFAULT 's', `cod_barra` varchar(50) DEFAULT NULL, `estoque` int(10) unsigned DEFAULT '10000', `estoque_minimo` int(10) unsigned DEFAULT '0', `estoque_maximo` int(10) unsigned DEFAULT '0', `estoque_seguranca` int(10) unsigned DEFAULT '0', `estoque_fiscal` int(10) unsigned DEFAULT '0', `setor` varchar(20) DEFAULT NULL, `bloco` varchar(20) DEFAULT NULL, `minimo_venda` int(10) unsigned DEFAULT '0', `peso_bruto` float unsigned DEFAULT '0', `peso_liquido` float unsigned DEFAULT '0', `embalagem` varchar(50) DEFAULT NULL, `ultima_compra` date DEFAULT NULL, `ultima_venda` date DEFAULT NULL, `ds` char(1) DEFAULT NULL, `da` char(1) DEFAULT NULL, `dv` char(1) DEFAULT NULL, `disponivel` char(1) DEFAULT NULL, `esgotado` char(1) DEFAULT NULL, `previsao_chegada` date DEFAULT NULL, `preco_custo` float unsigned DEFAULT '0', `dolar_compra` float unsigned DEFAULT '0', `custo_frete` float unsigned DEFAULT '0', `custo_funcionario` float unsigned DEFAULT '0', `custo_embalagem` float unsigned DEFAULT '0', `outras_despesas` float unsigned DEFAULT '0', `comissao_vendedor` float unsigned DEFAULT '0', `desconto_permitido` float unsigned DEFAULT '0', `margem_lucro` float DEFAULT '0', `preco_venda` float unsigned DEFAULT '0', `preco_fiscal` float unsigned DEFAULT '0', `tipo_fiscal` char(1) DEFAULT NULL, `ultima_alteracao` datetime DEFAULT NULL, `ultima_alteracao_img` datetime DEFAULT NULL, `cfop_dentro` int(4) unsigned DEFAULT NULL, `cfop_fora` int(4) unsigned DEFAULT NULL, `cfop_st_dentro` int(4) unsigned DEFAULT NULL, `cfop_st_fora` int(4) unsigned DEFAULT NULL, `origem` varchar(20) DEFAULT NULL, `uCom` varchar(6) DEFAULT NULL, `ncm` char(8) DEFAULT NULL, `extipi` char(3) DEFAULT NULL, `ipi` float unsigned DEFAULT '0', `cEnq` char(3) DEFAULT NULL, `CNPJProd` char(18) DEFAULT NULL, `cst` char(3) DEFAULT NULL, `orig` char(1) DEFAULT NULL, `modBC` char(1) DEFAULT NULL, `pICMS` float unsigned DEFAULT '0', `pRedBC` float unsigned DEFAULT '0', `modBCST` char(1) DEFAULT NULL, `pICMSST` float unsigned DEFAULT '0', `pRedBCST` float unsigned DEFAULT '0', `pMVAST` float unsigned DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5810 DEFAULT CHARSET=latin1; no caso o que eu preciso é o seguinte select * form mi_prdutos where estoque_fiscal >0; select v_comercial from mi_itens_nfiscal as mif where mif.codigo=mi_produtos.id if v_comercial =0 and v_comercial='' and v_comercial= null v_comercial := mi_produtos.preco_fiscal e pra complicar um pouquinho mais tenho que multiplicar esse valor pelo estoque fiscal. mais tem que ser tudo num sql só pois vou usar ele no ReportBuilder no Delphi