Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Select statements included within a function cannot return data to a client


Select statements included within a function cannot return data to a client

Author
Message
luan.wp
luan.wp
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 26
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
Ramesh Saive
Ramesh Saive
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2564 Visits: 2643
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


J-F Bergeron
J-F Bergeron
Say Hey Kid
Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)

Group: General Forum Members
Points: 711 Visits: 2707
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
luan.wp
luan.wp
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 26
tks!

Command(s) completed successfully.
Tom Waitman
Tom Waitman
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 50
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.



starshayiz
starshayiz
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 0
Hi,guys.I am new





Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search