473,396 Members | 2,158 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,396 software developers and data experts.

Using SELECT INTO within a Scalar Function

Hi Guys,

So i've just been told that SELECT INTO cannot be used within a scalar function. Can anyone please tell me why?

Secondly, can I use a cursor on a view? and all within a function?

Thirdly, if not, can I define a cursor on various fields from four different tables using INNER JOIN i.e.:

DECLARE cursor_name CURSOR local SCROLL
FOR SELECT p.field_one, q.field_two, r.field_one
FROM Product p INNER JOIN Query q
ON p.ProductID = q.ProductID
INNER JOIN Racing r
ON q.RoadID = r.RoadID
WHERE p.ProductID = @PurchaseOrderID

DECLARE VARIABLES HERE
OPEN CURSOR

I'm using SQL Server 2005 and working with the adventureworks sample database. Any help would be much appreciated.

Cheers,

Michelle
Aug 28 '07 #1
1 3638
azimmer
200 Expert 100+
Hi Guys,

So i've just been told that SELECT INTO cannot be used within a scalar function. Can anyone please tell me why?

Secondly, can I use a cursor on a view? and all within a function?

Thirdly, if not, can I define a cursor on various fields from four different tables using INNER JOIN i.e.:

DECLARE cursor_name CURSOR local SCROLL
FOR SELECT p.field_one, q.field_two, r.field_one
FROM Product p INNER JOIN Query q
ON p.ProductID = q.ProductID
INNER JOIN Racing r
ON q.RoadID = r.RoadID
WHERE p.ProductID = @PurchaseOrderID

DECLARE VARIABLES HERE
OPEN CURSOR

I'm using SQL Server 2005 and working with the adventureworks sample database. Any help would be much appreciated.

Cheers,

Michelle
I don't know what exact limits have been removed in SQL Server 2005 but in 2000 some of the limits imposed on functions is sometimes nasty. The workaround I use is either use a PROCEDURE instead of a function, or if it has to be a function I make up a procedure to do the job and create a wrapper function... I know of no better way.

To my knowledge there's no limit on using cursors on views - outside or within a function. Nearly any SELECT will do for a cursor so joining tables is perfectly OK.
Aug 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mario Pranjic | last post by:
Hi! I have a scalar function that returns integer: xview (int) Now, I'm trying to build a procedure that has the following select inside: select atr1, xview(atr2) from tablename
2
by: Martin MacRobert | last post by:
Hi, I'm trying to make a specialisation of a template function, so that the second parameter accepts scalar types only (int,double,float etc.). How can I do this without writing an explicit...
6
by: bryan.seaton | last post by:
I have a delete statement that is not doing what I want it to do: Delete from LOG_TABLE where (DATE(LOG_TS)) < (DATE(CURRENT_DATE)- 21 DAYS); It is supposed to delete all records that are 21...
21
by: kimimaro | last post by:
Is there anymore methods in exiting your program using pure C language other than return 0?
43
by: markryde | last post by:
Hello, I saw in some open source projects a use of "!!" in "C" code; for example: in some header file #define event_pending(v) \ (!!(v)->vcpu_info->evtchn_upcall_pending & \...
0
by: ZXDALMA | last post by:
Dear colleagues, I'm programming in ADS-OnLine Language attached to a DB2 V7R1 server which acts as a data repository. I need to know how to use the scalar function IDENTITY_VAL_LOCAL in order...
2
by: mcleana | last post by:
I have a view that contains a complex query. A few of the columns call a function that returns a specific output. I also use a function to do a join as well. For example: SELECT l.ID,...
0
by: srizzler | last post by:
Hi All: I am trying to implement Exception Handling using Enterprise Library 3.1's Exception Handling Application Block as well as Logging Blocks. I have a windows application developed in...
1
by: Arun Srinivasan | last post by:
I wrote an udf which can be outlined as create <> modifies sql data returns select * from old table (update <set <>); end; The error I get is SQL0278N SQL0628N Multiple or conflicting...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.