|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 08, 2010 12:42 PM
Points: 9,
Visits: 24
|
|
Hi,
i'm trying create on function, but the sql print:
Msg 444, Level 16, State 2, Procedure Retorna_UltimoLog, Line 9 Select statements included within a function cannot return data to a client.
somepeople,
can help me?
the query is
create function Retorna_UltimoLog (@codPromocao int) RETURNS varchar(200)
as BEGIN
declare @Descricao as varchar(200) select top 1 lt.txtDescricao from gpv_promocoes p
inner join GPV_Log l on p.codPromocao = l.cod_objeto inner join GPV_Log_Tipo lt on lt.cod_tipolog = l.cod_tipolog
where p.codPromocao = @codPromocao and lt.txtDescricao = @Descricao
order by l.cod_Log DESC Return @Descricao END
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Friday, February 22, 2013 12:03 AM
Points: 2,555,
Visits: 2,587
|
|
I suspect that the query is logically incorrect. Since you have declared the variable @Descricao but not assigned any value to it.
declare @Descricao as varchar(200)
select top 1 lt.txtDescricao from gpv_promocoes p inner join GPV_Log l on p.codPromocao = l.cod_objeto inner join GPV_Log_Tipo lt on lt.cod_tipolog = l.cod_tipolog where p.codPromocao = @codPromocao and lt.txtDescricao = @Descricao
--Ramesh
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Wednesday, February 13, 2013 7:40 AM
Points: 715,
Visits: 2,705
|
|
You need to assign the returning value from the select to the variable you declared.
Like that :
DECLARE @var nvarchar(200) select @var = top 1 field1 from table1
return @Var. That will fix your problem, but I think you should use an Inline function for that, just do this :
create function fn1 @Param nvarchar(100) returns nvarchar(200) as BEGIN Return (Select top 1 field1 from table1 where Field2 = @Param) END Hope it helps, if you need some working code, just tell me, I only put sample for you to understand.
Cheers,
J-F
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 08, 2010 12:42 PM
Points: 9,
Visits: 24
|
|
tks!
Command(s) completed successfully.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, March 28, 2013 10:04 PM
Points: 8,
Visits: 49
|
|
Thanks for the suggestion about the inline function. I am a real novice at writing functions and this quickly solved a problem that I was struggling with.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, November 15, 2012 7:33 PM
Points: 9,
Visits: 0
|
|
|
|
|