Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IF OBJECT_ID('fn_GetDiv') IS NOT NULL
- DROP FUNCTION fn_GetDiv
- GO
- CREATE FUNCTION fn_GetDiv(@idforn INT)
- RETURNS MONEY
- BEGIN
- DECLARE @ret MONEY;
- SET @ret = (SELECT SUM(TotalFactura-Pagamento-Crédito) FROM CópiaFacturas WHERE Fornecedor = @idforn)
- RETURN @ret
- END
- GO
- DECLARE Cursor_2Ponto3 CURSOR
- FORWARD_ONLY DYNAMIC READ_ONLY
- FOR
- SELECT IDFornecedor, Nome, Localidade
- FROM Fornecedores
- WHERE dbo.fn_GetDiv(IDFornecedor) > 0
- DECLARE @id INT, @n VARCHAR(150), @loc VARCHAR(150)
- OPEN Cursor_2Ponto3
- FETCH NEXT FROM Cursor_2Ponto3 INTO @id, @n, @loc
- WHILE @@FETCH_STATUS = 0
- BEGIN
- PRINT @n+'(' +@loc+')'
- PRINT 'Divida: ' + CONVERT(VARCHAR,dbo.fn_GetDiv(@id))
- PRINT ' '
- FETCH NEXT FROM Cursor_2Ponto3 INTO @id, @n, @loc
- END
- CLOSE Cursor_2Ponto3
- DEALLOCATE Cursor_2Ponto3
Advertisement
Add Comment
Please, Sign In to add comment