SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using a function on SELECT error


Using a function on SELECT error

Author
Message
luissantos
luissantos
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1231 Visits: 750
Hello comunity

I have create this function to return total pairs:

CREATE FUNCTION [dbo].[fnQtRefCor]
(@bostamp varchar(25), @ref varchar(20), @cor varchar(50))
RETURNS int
AS
BEGIN
DECLARE @retval int

SELECT @retval = SUM(qtt) FROM bi
WHERE @bostamp = bostamp AND @ref = ref AND @cor = cor
and bi.ref <> ''

SET @retval = ISNULL(@retval, 0)
RETURN @retval
END

If i run this query:
SELECT SUM(qtt) FROM bi
WHERE bostamp = 'jm13010767476,323000001' AND ref = '2120910'
and (bi.ref <> '')
group by bi.bostamp,ref,cor

I obtain the correct value of : 24

if i run this select to test the result :
select [dbo].[fnQtRefCor] from bi where bi.bostamp = 'jm13010767476,323000001 '

This error appear :
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.fnQtRefCor" could not be bound.

I can run this SELECT without error ?

Many thanks,
Luis Santos



luissantos
luissantos
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1231 Visits: 750
Sorry, i forget to mencioned that the compatibility level is :
SQL SERVER 2000 (80)

Maybe the problem is here ??

Thanks



Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)

Group: General Forum Members
Points: 92231 Visits: 38954
luissantos (1/13/2013)
Hello comunity

I have create this function to return total pairs:

CREATE FUNCTION [dbo].[fnQtRefCor]
(@bostamp varchar(25), @ref varchar(20), @cor varchar(50))
RETURNS int
AS
BEGIN
DECLARE @retval int

SELECT @retval = SUM(qtt) FROM bi
WHERE @bostamp = bostamp AND @ref = ref AND @cor = cor
and bi.ref <> ''

SET @retval = ISNULL(@retval, 0)
RETURN @retval
END

If i run this query:
SELECT SUM(qtt) FROM bi
WHERE bostamp = 'jm13010767476,323000001' AND ref = '2120910'
and (bi.ref <> '')
group by bi.bostamp,ref,cor

I obtain the correct value of : 24

if i run this select to test the result :
select [dbo].[fnQtRefCor] from bi where bi.bostamp = 'jm13010767476,323000001 '

This error appear :
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.fnQtRefCor" could not be bound.

I can run this SELECT without error ?

Many thanks,
Luis Santos




One thing I see is that you aren't passing in any parameters to the function.

Try the following with the proper values for the parameters.

select [dbo].[fnQtRefCor](@bostamp = ??, @ref = ??, @cor= ??);

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
luissantos
luissantos
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1231 Visits: 750
Hello Lynn Pettis

Yes, you are right i forget my parameters (bostamp,ref,cor)

Thanks for your reply
Luis Santos



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