Вопрос

When I execute a stored proc via cfstoredproc, I am getting a different result than calling that stored proc via cfquery. I am passing in the same exact parameter values to each call. And also, when I run the stored proc in SQL Studio, I get the correct results (same as the cfquery).

Here's the cfstoredproc call

<cfstoredproc datasource="#request.mainDSN#" debug="#request.debug#" procedure="rankingresults">
   <cfprocparam type="in" value="8652" CFSQLType="CF_SQL_INTEGER">
   <cfprocparam type="in" value="50" CFSQLType="CF_SQL_INTEGER">
   <cfprocparam type="in" value="53" CFSQLType="CF_SQL_INTEGER">
   <cfprocresult name="local.listing">
</cfstoredproc>

Here is the cfquery call

<cfquery datasource="#request.mainDSN#" name="rankings">
   EXEC rankingresults
    @CityZipId = 8652,
    @distance = 50,
    @sic = 53
</cfquery>

The results are completely different. It's not even close. I've been banged my head over this for several hours, and I can't figure out why it is doing what it is doing.

UPDATE

The stored proc is massive (and one that I inherited), so I'm not going to paste it all here: http://pastebin.com/EtufPWXf

Это было полезно?

Решение

(From the comments)

Looks like it does have optional parameters. So your cfstoredproc call may not be passing in the values you think it is. Based on the order, it looks like it is actually passing in values for: @CityZipID, @Sic, @lastRank. As Dan mentioned (and I hinted at), cfstoredproc uses positional notation for parameters (@dbVarName is deprecated). You need to supply all of the parameter values in the correct order.

Update:

FWIW, if you create a shell procedure you would see the cfstoredproc and cfquery are actually invoking the procedure with different parameters/values. (See below).

You would definitely see a difference in results if you invoked the procedure without the named parameters as @Dan suggested ie exec rankingresults 8652, 50, 53. (I know you said there was "no change", but there was probably just an error in your test).

CFSTOREDPROC

@ATTRCODES|@CITYZIPID|@DISTANCE|@HASURL |@ISFEATURED |@LASTRANK|@PHOTOCOUNT|@REVIEWCOUNT |@SIC|@SICBUDGETIDS 
(nothing)| 8652| (nothing)| (nothing)| (nothing)| 53| (nothing)| (nothing)| 50| (nothing)

CFQUERY

@ATTRCODES|@CITYZIPID|@DISTANCE|@HASURL |@ISFEATURED |@LASTRANK|@PHOTOCOUNT|@REVIEWCOUNT |@SIC|@SICBUDGETIDS 
(nothing)| 8652| 50| (nothing)| (nothing)| 0| (nothing)| (nothing)| 53| (nothing)

Другие советы

If you run this directly on the sql server how many results does it return? You could be returning multiple results that could explain the difference in behavior.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top