?
Solved

calling stored proc from CF

Posted on 2006-10-26
3
Medium Priority
?
193 Views
Last Modified: 2013-12-24
Hi, dear CF experts,

This my first sp call from CF. I got Invalid CFML construct on last CFIF statement. Here is my cf code and sp itself, which I have tested successfully in sql.

<cfstoredproc datasource="QWSQL" procedure="Web_CheckLastLogin" returncode="No">
  <cfprocresult name="MonthSinceLastLogin" resultset="1">
<CFPROCPARAM TYPE="IN"
    DBVARNAME="@p1"
    VALUE=login.user_id
 CFSQLTYPE="CF_SQL_LONGVARCHAR">
<CFPROCPARAM TYPE="OUT"
    DBVARNAME="@MonthSinceLastLogin"
    Variable = m_Months
    CFSQLTYPE="CF_SQL_SMALLINT">
</cfstoredproc>
<cfif  m_Months LG 2>
     <cflocation url ="MaintainAcct.cfm?user_id>
</cfif>

CREATE PROCEDURE [dbo].[Web_CheckLastLogin]
       @p1 varchar(10) ,
@MonthSinceLastLogin smallint output
AS
SET NOCOUNT ON
select @MonthSinceLastLogin = datediff(mm,  
(select max(time_occured) from web_history where script_name ='/cust/login.cfm'
and [user_id] =@p1),
getdate())
return @MonthSinceLastLogin
SET NOCOUNT OFF
GO

Thanks a lot!
0
Comment
Question by:ommer
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
trailblazzyr55 earned 500 total points
ID: 17815294
you had some syntax errors... try this...

<cfstoredproc datasource="QWSQL" procedure="Web_CheckLastLogin" returncode="No">
  <cfprocresult name="MonthSinceLastLogin" resultset="1">
  <CFPROCPARAM TYPE="IN" DBVARNAME="@p1" VALUE="#login.user_id#" CFSQLTYPE="CF_SQL_LONGVARCHAR">
                                                                  <!--- ------------------^ here ----- --->
  <CFPROCPARAM TYPE="OUT" DBVARNAME="@MonthSinceLastLogin" Variable="m_Months" CFSQLTYPE="CF_SQL_SMALLINT">
                                                                                       <!--- ---------------and---^ here ----- --->
</cfstoredproc>
<cfif  m_Months LG 2>
     <cflocation url ="MaintainAcct.cfm?user_id>
</cfif>
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17815345
You can also called a stored proc like so.....
-------------------------------------------------------------
<cfquery datasource="YourDSN" name="MyQuery">
   {call dbo.Web_CheckLastLogin ('#login.user_id#')}
</cfquery>


<cfdump var="#MyQuery#"> <!--- dump to see results --->





and have your stored procedure like so....
-------------------------------------------------------------
CREATE PROCEDURE [dbo].[Web_CheckLastLogin]
      @p1 varchar(10)
AS
SET NOCOUNT ON
DECLARE @MonthSinceLastLogin smallint
select @MonthSinceLastLogin = datediff(mm,(select max(time_occured) from web_history where script_name ='/cust/login.cfm' and [user_id] =@p1),getdate())
SET NOCOUNT OFF
GO
0
 

Author Comment

by:ommer
ID: 17821527
Cool! I like the 2nd way for its simplicity!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 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