[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Table-Valued Function in Query

Posted on 2007-10-13
1
Medium Priority
?
512 Views
Last Modified: 2008-01-09
I have a table with the following fields (greatly simplified):

[OLDDATA]
Item, Description, ID, Acc1, Acc2, Acc3, Acc4, Acc5, Acc6
Sample data
22,Description,88,null,y,null,null,y,null

I am writing a procedure which takes this data and moves it into a properly normalised table, which will have the following fields:

Item, Description, ID, Office

The Office field value is determined by the values in Acc1, 2, 3 etc and so there may be between 1 and 6 records copied to the new table depending on the contents of these 6 fields.  I have written a table-valued function which examines these fields and returns a table with one field thus:

Office
01
29
83
etc

My question is:  How do I link this function into a select query so that I can get this result:

Item, Description, ID, Office
22,Description,88,01
22,Description,88,29
22,Description,88,83
etc

I'm looking for something like this (which obviously doesn't work):

SELECT O.Item, O.[Description], O.ID, N.Office
FROM [OLDDATA] O,
[dbo].[MYFUNCTION] (O.Acc1, O.Acc2, O.Acc3, O.Acc4) N
0
Comment
Question by:Spunkymungbeans
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 20071001
sql server 2005: discover the CROSS APPLY keyword:

SELECT O.Item, O.[Description], O.ID, N.Office
FROM [OLDDATA] O
CROSS APPLY [dbo].[MYFUNCTION] (O.Acc1, O.Acc2, O.Acc3, O.Acc4) N
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question