Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem using parameters in a stored procedures when querying against a AS400 Linked Server

Posted on 2006-06-25
10
Medium Priority
?
386 Views
Last Modified: 2008-01-09
I have the following stored procedure,

CREATE PROCEDURE [dbo].[SelectAccidentContacts]

@Param bigint

AS

SELECT FieldA,  FieldB, FieldC
FROM LINKEDSERVER.AS400.AS400LIBRARY.FILENAME
WHERE (FieldA= @Param)

GO

When I execute this passing the @Param as a paramater it generates the following error.

OLE DB provider 'MSDASQL' reported an error. The provider reported an unexpected catastrophic failure.
OLE DB error trace [OLE/DB Provider 'MSDASQL' ICommandText::Execute returned 0x8000ffff:  The provider reported an unexpected catastrophic failure.].

If I change @Param to a fixed value it works OK (IE - WHERE (FieldA= 1234567).

I can set the fixed value as a string by encapsulating it in ' ' or just as a number and both work but no matter what datatype I use for the parameter it still returns the same error.

The DataType on the As400 is numerical with a length of 7 with no decimals.

I am currently trying to prove a concept for a new project and if I can't get this to work then my concept goes out the window so any help to resolve this would be greatly appreciated!
0
Comment
Question by:RayDaly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 4

Expert Comment

by:kenpem
ID: 16978343
silly, silly question: is there a type in your example? Your procedure declares @Param as a parameter, but you try to validation against the non-existent variable @AccNo. Either change @Param to @Accno or vice versa. I'll be very surprised if SQL even accepts the procedure with an error like this in!
0
 

Author Comment

by:RayDaly
ID: 16978347
Sorry, that was me changing the paramater names & field names for this example, the paramater names are correct in my sp!!
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16978397
change your procedure to be

CREATE PROCEDURE [dbo].[SelectAccidentContacts]

@Param bigint

AS

SELECT FieldA,  FieldB, FieldC
FROM openquery (LINKEDSERVER, 'select * from AS400.AS400LIBRARY.FILENAME')

WHERE (FieldA= @Param)

GO
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:RayDaly
ID: 16978439
OK Thanks, getting somewhere now. This does work but the OPENQUERY statement only selects a limited number of records from the AS400 table to query against, 107 to be precise, and there a 1000's in there.


 
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16978494
RUN THIS QUERY TO CHECK HOW MANY RECORDS YOU HAVE IN YOUR TABLE
===================================================
Are you aware that the above mentioned post you are filtering the rows by mentioning the criteria of WHERE (FieldA= @Param)


SELECT count(*)
FROM openquery (LINKEDSERVER, 'select * from AS400.AS400LIBRARY.FILENAME')

and

SELECT *
FROM openquery (LINKEDSERVER, 'select count(*) from AS400.AS400LIBRARY.FILENAME')
0
 

Author Comment

by:RayDaly
ID: 16978530
Thanks but already did run this query to determine the number of rows, came back with 107. I seem to remeber when I was looking for the answer to my original problem that there is a restricted number of bytes that gets returned from a linked server by default and there's some way to increase it. Trying to hunt it down now.
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16978555
ok
0
 

Author Comment

by:RayDaly
ID: 16978933
Still no Joy, gonna give up for today. Thanks for you help imram, atleast I've got the params working!
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17528334
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

609 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