MSSQL/TOTVS – Função que pega o nome fantasia

Passa a coligada e o id do movimento

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
USE [CORPORERM]
GO
/****** Object:  UserDefinedFunction [dbo].[GET_NOME_FANTAZIA]    Script Date: 08/11/2015 09:47:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[GET_NOME_FANTAZIA]
(
	-- Add the parameters for the function here
	@CODCOLIGADA INT,
	@IDMOV INT--,
	--@CODTMV VARCHAR(10)
)
RETURNS VARCHAR(50)
AS
BEGIN
	DECLARE @RET VARCHAR (50)
 
	select @RET = (select max(NOMEFANTASIA) from fcfo where CODCOLIGADA = 0 and CODCFO = TMOV.CODCFO) from TMOV where idmov = @IDMOV and CODCOLIGADA = @CODCOLIGADA
 
	RETURN @RET
END