Solved

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

Posted on 2006-06-25
10
348 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
10 Comments
 
LVL 4

Expert Comment

by:kenpem
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:RayDaly
Comment Utility
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 28

Expert Comment

by:imran_fast
Comment Utility
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
Comment Utility
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
Comment Utility
ok
0
 

Author Comment

by:RayDaly
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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 setup several different housekeeping processes for a SQL Server.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now