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

SQL server multi-statement table function w/ openquery

zachster17
Hello all,

I'm trying to write a multi-statement table function that returns a table of addresses from a remote database (Oracle) using OpenQuery and I'm having a hard time getting it to work with the 1 variable constraint it has (provider ID)

The code is below:

Expand|Select|Wrap|Line Numbers
  1. SET ANSI_NULLS ON
  2. GO
  3. SET QUOTED_IDENTIFIER ON
  4. GO
  5.  
  6. CREATE FUNCTION pmf_udfProviderChangeAddressTable
  7. (
  8.     -- Add the parameters for the function here
  9.     @ProviderID varchar(20)
  10. )
  11. RETURNS @AddressTable TABLE
  12. (
  13.     -- Add the column definitions for the TABLE variable here
  14.     ContactType varchar(4),
  15.     ContactAddr1 varchar(100),
  16.     ContactAddr2 varchar(100),
  17.     ContactCity varchar(40),
  18.     ContactState varchar(3),
  19.     ContactZip varchar(10),
  20.     ContactPhone varchar(20),
  21.     ContactFax varchar(20)
  22. )
  23. AS
  24. BEGIN
  25.  
  26.     DECLARE @SQL As varchar(500)
  27.     SET @SQL = 'SELECT CONTACT_TYPE As ContactType, FIRM_NAME As ContactAddr1,
  28.     ADDRESS_LINE1 As ContactAddr2, CITY AS ContactCity, STATE As ContactState, ZIP_CODE As ContactZip,
  29.     PHONE_NBR As ContactPhone, FAX_NBR As ContactFax FROM NET$.CONTACTS
  30.     WHERE PROV_ID = ''' + @ProviderID + ''' AND
  31.     (CONTACT_TYPE = ''01'' OR CONTACT_TYPE = ''02'')'
  32.  
  33.  
  34.     -- Add the SELECT statement with parameter references here
  35.     EXEC('INSERT INTO @AddressTable SELECT * FROM OPENQUERY(ENCP, ' + @SQL + ')'
  36.  
  37.     RETURN 
  38. END
  39. GO
  40.  
I keep getting this error:

Msg 156, Level 15, State 1, Procedure pmf_udfProviderChangeAddressTable, Line 33
Incorrect syntax near the keyword 'RETURN'.


Let me know if you need any more info.

Thank you!

Zach
Feb 19 '08 #1
1 4349
ck9663
2,878 Expert 2GB
I think you're missing one close parenthesis on your EXEC statement. You have ')' to close the OPENQUERY, but missing one to close the EXEC statement.

-- CK
Feb 19 '08 #2

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

Similar topics

7
by: rdh | last post by:
Hi all, I am in process of developing a Server in C++ supporting multiple protocols. The server will be exposing various functionalities, and the clients can communicate over any of the...
0
by: Zorba.GR | last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64 bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
10
by: Zeng | last post by:
I just realized that there are 2 modes for garbage collection modes: server gs and workstation gs. Would someone know how I can go about changing the mode for my web application written in C#? I...
17
by: Danieltbt05 | last post by:
just installed SQL server 2000 and using my client , i can't locate the server. I used SQL query analyzer to search but no servers were found. Error message is as below Server : Msg17,level...
2
by: NiponW | last post by:
Hi, I have SQL SERVER 2000 SP4 Enterprise , Windows 2003 Enterprise on Xeon 4 Processors (now with multi-threading CPU) and I have questions which seem weirds to me (used to have the same...
4
by: dorpnospam | last post by:
We have an old but very critical application that was written in VB 6 against Access 95 dbs. We need to ditch this decrepit old unstable db platform but we are trying to determine the best...
9
by: TC | last post by:
Like a lot of database developers, I often choose Jet for the back- end. I'm starting to worry about what will happen when Jet is deprecated. Ostensibly, Jet users like me must switch to SQL Server...
0
by: uninvitedm | last post by:
I'm making a JSP page where (ideally) you select files to upload, each selected file is added to a listbox. The form is submit, (along with some other parameters), and the files are uploaded. They...
2
by: praveenkumarvpk | last post by:
Hi friends Please help me! Following is my servlet-code import java.util.Enumeration; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import...
14
by: Guillermo_Lopez | last post by:
Hello, Our company has developed several Access applications for our clients and we wish to expand to use a database server. We wish to use Access as the front end application and SQL Server...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.