alter procedure sp_package_has_inventory
@packageID INT
, @hasInventory INT OUT
as
begin
--- change output var
set @hasInventory = 285
--- generate two resultsets
select @packageID AS Value1
select 99 AS Value2
end
go
- Railo 3.1.2 / MS SQL 2005 / MS SQL OR JTDS driver
* Assuming @showInsufficientProducts = 1
So as not to overlook the obvious, it return the correct when you run the procedure directly in the database (with the same parameters)? Also, are you using SET NOCOUNT ON inside the procedure?
-Leigh
--- Test Procedure
ALTER PROCEDURE sp_package_has_inventory
@packageID INT
, @hasInventory BIT OUT
, @showInsufficientProducts BIT = 1
AS
BEGIN
SET NOCOUNT ON
SET @hasInventory = 1
--- create and populate table1
CREATE TABLE #insuffient_inv_tbl ( Value1 INT )
INSERT INTO #insuffient_inv_tbl ( Value1 ) VALUES (999)
--- create and populate table2
CREATE TABLE #inv_tbl ( package_id INT, hasInventory BIT )
INSERT INTO #inv_tbl (package_id, hasInventory) VALUES (@packageID, @hasInventory)
--- generate resultset1
SELECT * FROM #inv_tbl
--- generate resultset2
IF @showInsufficientProducts = 1
SELECT * FROM #insuffient_inv_tbl
SET NOCOUNT OFF
END
GO
I do not know if it makes a difference, but it could not hurt to use an explicit resultset number for both cfprocresult's.
-Leigh
CREATE PROCEDURE ....
... parameters
AS
BEGIN
SET NOCOUNT ON
... rest of sql ....
SET NOCOUNT OFF
END
GO
-Leigh
> I'll do some research to see if there
> will be any potential problems using them.
Glad to hear it resolved. There should not be any issues with it. We use it all the time. It just suppresses extra communication that is normally discarded anyway. So there is a minute performance benefit as well.
> Also, Adobe CF never minds without SET NOCOUNT ON/OFF...
It has been a while, so I do not recall how ACF handles procedures without it. I do remember ACF 8 had similar issues when certain compound statements were used within cfquery (ie INSERT INTO/SCOPE_IDENTITY()) which varied by driver. So consistently using SET NOCOUNT is a good policy. Then you do not have to worry about this kind of issue cropping up due to changes in version, engine or database driver ;-)
-Leigh
IMO that much sql logic belongs in a stored procedure, not a cfquery. But unless there is more to it (?) .. you could greatly simplify the whole thing by removing the #temp tables. Create a permanent hours table instead of recreating a temporary one every time. Then join it to a derived query that returns today's hours
ie
SELECT a.dayHour, isNull(b.VisitCount, 0) as visitCount
FROM PermHoursTable a LEFT OUTER JOIN
(
SELECT DatePart(hour, datemodified) as dayHour, COUNT(counterid) as visitCount
FROM tblSession
WHERE datemodified >= ... etc...
GROUP BY DatePart(hour, datemodified)
) b on a.dayHour = b.dayHour
ORDER BY a.dayHour
-Leigh
That is odd. When I ran your original sql earlier, both ACF and Railo complained about the pre-existing temp table the second time the code was executed. So I added the missing drop table statements, just before the set nocount off.
However I did notice
a) The original sql (plus the drop table statements) worked fine as a stored procedure, called with cfstoreproc
b) The query result *did* exist when I used the jtds driver instead of the ms vendor driver.
-Leigh
I think Koofka mentioned he just forgot to include the "drop table..." statements in his original post. But you are right. Temp tables should be dropped at the end of the query. So they do not cause problems if an open db connection is reused.
> does the code work in Adobe CF?
It works with CF9/Adobe Driver and Railo/jTDS driver. It did *not* work with either engine when using the MS SQL Vendor Driver (v1.0?). That suggests a possible driver problem.
-Leigh