Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Using a function on SELECT error
Using a function on SELECT error
Rate Topic
Display Mode
Topic Options
Author
Message
luissantos
luissantos
Posted Sunday, January 13, 2013 10:02 AM
SSC Veteran
Group: General Forum Members
Last Login: Tuesday, March 05, 2013 10:34 AM
Points: 244,
Visits: 480
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
Post #1406482
luissantos
luissantos
Posted Sunday, January 13, 2013 10:05 AM
SSC Veteran
Group: General Forum Members
Last Login: Tuesday, March 05, 2013 10:34 AM
Points: 244,
Visits: 480
Sorry, i forget to mencioned that the compatibility level is :
SQL SERVER 2000 (80)
Maybe the problem is here ??
Thanks
Post #1406483
Lynn Pettis
Lynn Pettis
Posted Sunday, January 13, 2013 10:28 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:10 PM
Points: 21,588,
Visits: 27,380
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= ??);
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)
Post #1406489
luissantos
luissantos
Posted Sunday, January 13, 2013 10:35 AM
SSC Veteran
Group: General Forum Members
Last Login: Tuesday, March 05, 2013 10:34 AM
Points: 244,
Visits: 480
Hello Lynn Pettis
Yes, you are right i forget my parameters (bostamp,ref,cor)
Thanks for your reply
Luis Santos
Post #1406492
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.