Quantcast
Channel: Programação de Function
Viewing all articles
Browse latest Browse all 3

Programação de Function

$
0
0

Respondi neste fórum:

http://forum.imasters.com.br/topic/521342-programacao-de-function

Mas segue a resposta:

IF EXISTS (select 1 from sys.objects where name  = 'rendaCliente' and type = 'FN')
drop function rendaCliente
GO
CREATE function rendaCliente (@Codigo int)
returns float
as
begin
declare @renda float
SELECT  @renda = (isnull(a.renda,0) + isnull(b.renda_conjuge,0))
from cliente a 
left join conjuge b on a.cod = b.codCliente
WHERE a.cod = @Codigo
and upper(a.estadoCivil) = 'CASADO'
return @renda
end
select *, dbo.rendaCliente(a.cod) as renda_total from cliente a  left join conjuge b on a.cod = b.codCliente


Viewing all articles
Browse latest Browse all 3


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>