Hey,
I'm trying to get thru a syntax problem (probably), but can't
find the right solution...
Here's the thing, I have the following stored procedure in my
SQL 2005 database:
CREATE PROCEDURE [dbo].[spPlanningCheck_s]
(
@PID nvarchar(2000) = NULL,
@pEmployeeId uniqueidentifier,
@pDatestart datetime,
@pDateend datetime,
@pProjectId int = NULL,
@pPlanningIds varchar(1000) = NULL
)
AS
BEGIN
DECLARE @iError int
SET NOCOUNT ON
SELECT * FROM tblPLANNING
WHERE fk_employee_id = @pEmployeeId
AND datediff(day, tblPLANNING.datestart, @pDateend) >= 0
AND datediff(day, tblPLANNING.dateend, @pDatestart) <= 0
AND (@pProjectID IS NULL OR (@pProjectId IS NOT NULL AND
fk_project_id = @pProjectId))
AND (@pPlanningIds IS NULL OR (@pPlanningIds IS NOT NULL AND
id NOT in (@pPlanningIds)))
ORDER BY datestart
SELECT @iError = @@error
IF @iError <> 0
BEGIN
GOTO error_section
END
GOTO end_section
error_section:
end_section:
RETURN @iError
END
I've been trying to call this procedure with a cfstoredproc,
but cfstoredproc doesn't understand the concept of 'list'.
So I used my work around : cfquery. Unfortunatly, cfquery
doesn't seem to accept my uniqueidentifier?
So I'm at a complete loss...
Here are the 2 options I tried:
<cffunction
name="checkPlanning"
access="public"
returntype="query"
output="false"
hint="Check planning">
<cfargument name="iPlanningId" type="numeric"
required="false" default="-1">
<cfargument name="iEmployeeId" type="guid"
required="true">
<cfargument name="dStartdate" type="date"
required="true">
<cfargument name="dEnddate" type="date"
required="true">
<cfargument name="iProjectId" type="numeric"
required="false" default="-1">
<cfargument name="sPlanningIds" type="string"
required="false" default="-1">
<cfstoredproc
datasource="#application.stApplicationData.sDataSource#"
procedure = "spPlanningCheck_s" returncode="true"
debug="#session.stuserdata.bdebugmode#"
>
<cfif arguments.iPlanningId EQ -1>
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER"
dbvarname="@pId" null="true">
<cfelse>
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER"
dbvarname="@pId" value="#arguments.iPlanningId#">
</cfif>
<cfprocparam type="In"
cfsqltype="CF_SQL_UNIQUEIDENTIFIER" dbvarname="@pEmployeeId"
value="#arguments.iEmployeeId#">
<cfprocparam type="In" cfsqltype="CF_SQL_TIMESTAMP"
dbvarname="@pDatestart" value="#arguments.dStartdate#">
<cfprocparam type="In" cfsqltype="CF_SQL_TIMESTAMP"
dbvarname="@pDateend" value="#arguments.dEnddate#">
<cfif arguments.iProjectId EQ -1>
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER"
dbvarname="@pProjectId" null="true">
<cfelse>
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER"
dbvarname="@pProjectId" value="#arguments.iProjectId#">
</cfif>
<cfif arguments.sPlanningIds EQ -1>
<cfprocparam type="In" cfsqltype="CF_SQL_STRING"
dbvarname="@pPlanningIds" null="true">
<cfelse>
<cfprocparam type="In" cfsqltype="CF_SQL_STRING"
dbvarname="@pPlanningIds" value="#arguments.sPlanningIds#">
</cfif>
<cfprocresult name="qResult">
</cfstoredproc>
<cfif cfstoredproc.statusCode NEQ 0>
<cfmodule
template="#application.stApplicationData.sCFMapping#customtags/logging.cfm"
sModule="PlanningData.getPlanning" sMessage="Stored Procedure
Failed: #cfstoredproc.statusCode#">
</cfif>
<cfreturn qResult>
</cffunction>
Option 2:
<cffunction
name="checkPlanning"
access="public"
returntype="query"
output="false"
hint="Check planning">
<cfargument name="iPlanningId" type="string"
required="false" default="NULL">
<cfargument name="iEmployeeId" type="guid"
required="true">
<cfargument name="dStartdate" type="date"
required="true">
<cfargument name="dEnddate" type="date"
required="true">
<cfargument name="iProjectId" type="numeric"
required="false" default="NULL">
<cfargument name="sPlanningIds" type="string"
required="false" default="NULL">
<cfquery name="qResult"
datasource="#application.stApplicationData.sDataSource#">
DECLARE @RC int
DECLARE
@PID nvarchar(2000)
DECLARE @pEmployeeId uniqueidentifier
DECLARE @pDatestart datetime
DECLARE @pDateend datetime
DECLARE @pProjectId int
DECLARE @pPlanningIds varchar(1000)
<!--- Use tostring to convert the seemingly string into a
string the database can handle... --->
EXEC @RC = [PRS].[dbo].[spPlanningCheck_s]
#arguments.iPlanningId#,
@pEmployeeId="#tostring(arguments.iEmployeeId)#",
#arguments.dStartdate#, #arguments.dEnddate#,
#arguments.iProjectId#, #tostring(arguments.sPlanningIds)#
</cfquery>
<cfreturn qResult>
</cffunction>
Summary:
- Why doesn't cfstoredproc work with lists?
- Why doens't cfquery work with uniqueidentifiers?