473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Use of user defined in SELECT clause

I'm having this query:

SELECT
ss.subscription_id AS SubscriptionId,
s.id AS ScopeId,
s.[name] AS ScopeName,
s.base AS ScopeBase,
dbo.iqGetShapesByScopeAsString(s.id) AS ShapesAsString

FROM
subscription_scope ss,
scope s

WHERE
ss.subscription_id = @subscription_id
AND
ss.scope_id = s.id

ORDER BY
s.[name]
The select only returns a single row but my database (SQL Server 2005
CTP) seems to execute the "iqGetShapesByScopeAsString" function for
each row in the subscription_scope and scope tables. This is a bug,
right? The function should be executed only once for each *returned*
row in the SELECT, right? I believe that was the case in SQL 2k though
I can't check it at the moment.

// pt

Jul 23 '05 #1
6 1342
[posted and mailed, please reply in news]

Peter Theill (th****@gmail.com) writes:
I'm having this query:

SELECT
ss.subscription_id AS SubscriptionId,
s.id AS ScopeId,
s.[name] AS ScopeName,
s.base AS ScopeBase,
dbo.iqGetShapesByScopeAsString(s.id) AS ShapesAsString

FROM
subscription_scope ss,
scope s

WHERE
ss.subscription_id = @subscription_id
AND
ss.scope_id = s.id

ORDER BY
s.[name]

The select only returns a single row but my database (SQL Server 2005
CTP) seems to execute the "iqGetShapesByScopeAsString" function for
each row in the subscription_scope and scope tables. This is a bug,
right? The function should be executed only once for each *returned*
row in the SELECT, right? I believe that was the case in SQL 2k though
I can't check it at the moment.


How do you know that function is executed for each row? If this is really
the case, I bet the SQL Server team would like to hear about it. Therefore
the right place to race the issue is one the
microsoft.private.sqlserver2005.* groups. See here for access information
to these groups: http://go.microsoft.com/fwlink/?linkid=31765.

Exactly which CTP are you seeing this on? The latest is the Jiune CTP,
aka CTP15. If you don't have that version, maybe you should download
and see if the problem persists.

I did an attempt to recreate the problem, but the repro below did not
exhibit the problem. You might want to use the trick I use with
xp_cmdshell to verify that the procedure is actually called once
for each row.

CREATE TABLE kilroy(OrderID int NOT NULL)
go
CREATE FUNCTION kilroy_was_here (@OrderID int) RETURNS INT AS
BEGIN
DECLARE @sql nvarchar(MAX), @sqlcmd varchar(255)
SELECT @sql = 'INSERT kilroy(OrderID) VALUES(' + str(@OrderID) + ')'
SELECT @sqlcmd = 'SQLCMD -d tempdb -Q "' + @sql + '"'
EXEC master..xp_cmdshell @sqlcmd
RETURN 8
END
go
SELECT O.OrderID, O.EmployeeID, C.CompanyName,
dbo.kilroy_was_here(O.OrderID)
FROM Northwind..Orders O, Northwind..Customers C
WHERE O.CustomerID = C.CustomerID
AND C.CustomerID = N'BERGS'
ORDER BY O.OrderID
go
SELECT * FROM kilroy
go
DROP TABLE kilroy
DROP FUNCTION kilroy_was_here


--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
>>
How do you know that function is executed for each row? If this is
really
the case, I bet the SQL Server team would like to hear about it.
Therefore
the right place to race the issue is one the
microsoft.private.sqlserver2005.* groups. See here for access
information
to these groups: http://go.microsoft.com/fwlink/?linkid=31765.
<<

I ran a profiler and saw several calls relating to my cursor used in
the UDF (open cursor, fetch next, etc). I agree that I have to post it
but it takes a couple of days to get the betaId so I just wanted to
know if it was me.

Exactly which CTP are you seeing this on? The latest is the Jiune CTP,
aka CTP15. If you don't have that version, maybe you should download
and see if the problem persists.
<<

I'm using the CTP working with the Whidbey (VS.NET 2005) beta 2
release. I haven't tried newer CTP since I'm not sure if these will
work with the above version.


I did an attempt to recreate the problem, but the repro below did not
exhibit the problem. You might want to use the trick I use with
xp_cmdshell to verify that the procedure is actually called once
for each row.
<<

Thanks, I'll give it a try.

Jul 23 '05 #3
Peter Theill (th****@gmail.com) writes:
I ran a profiler and saw several calls relating to my cursor used in
the UDF (open cursor, fetch next, etc).
You didn't mention any cursor in your first post?
I agree that I have to post it but it takes a couple of days to get the
betaId so I just wanted to know if it was me.


Not really sure where the beta id comes in, but you don't need any
betaid to post to the microsoft.private.sqlserver2005.* groups.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
>>
You didn't mention any cursor in your first post?
<<

I'm using a cursor in my user defined function.


Not really sure where the beta id comes in, but you don't need any
betaid to post to the microsoft.private.sqlserver2005.* groups.
<<

Sorry, maybe a stupid question but where do I access these newsgroups?
They're not available on "news.microsoft.com".

Jul 23 '05 #5
Peter Theill (th****@gmail.com) writes:
Sorry, maybe a stupid question but where do I access these newsgroups?


See http://go.microsoft.com/fwlink/?linkid=31765. (A link that I've
already posted once in the thread.)
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #6
>>
See http://go.microsoft.com/fwlink /?linkid=31765. (A link that I've
already posted once in the thread.)
<<

Yeah, ok ;-)

I'll post my message there .. thanks.

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joel Thornton | last post by:
Is it possible to call a user-defined function without prefixing it with 'dbo.' within a SELECT clause somehow? Just curious; it's not a big issue but just a stylistic one for me. Thanks! ...
5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
4
by: Sameer Deshpande | last post by:
How do I create and return user defined data types in DB2. F.ex In Oracle I can create a user define datatype and return this data type from stored function. How can I do the same in DB2? ...
2
by: David Emme | last post by:
Access 97 I have a number of SELECT statements which contain references to user-defined VBA functions. These typically work as expected, but occasionally, on one user's machine or another,...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
26
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND...
0
by: TertiaryKey | last post by:
Firstly I would like to say hello to you all as I am a new member. I'm calling a User Defined Function 'FormatDate' from DB2 SQL on an AS/400. The UDF receives a CYYMMDD numeric date and returns a...
0
FishVal
by: FishVal | last post by:
Hereby I'm proposing a way of convinient work with properties containing SQL Select statements, particulary RowSource property of ComboBox and ListBox. The usual way is the following. Private...
0
by: jefftyzzer | last post by:
Friends: In v8 or v9 LUW, if I were to write (in Java or C) my own user-defined aggregate function, would I be able to use it in an OLAP windowing clause as I could use, e.g., COUNT or SUM? ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.