a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

problem with function

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> problem with function
Page: [1]
 
adam2804

 

Posts: 34
Joined: 6/6/2006
Status: offline

 
problem with function - 9/13/2006 10:53:06   
Hello,

can anyone spot any problems with this function I am trying to use on for a DRW? Within my database program it returns 1626 but when I use it within FP it returns only 427.



/*
 FN_InvoiceList
 Function used to produce invoices
*/

--  NP Adding SupportContract_ID to returned result, needed for ContractManager
--  NP Adding Description to returned result, needed for ContractManager
--  NP Adding ProductCode, TAS_ID, CutomerRef needed for Contract Manager
--  NP Adding InvoicedToTAS to checnk if the invoice has been sent to TAS


CREATE         FUNCTION FN_InvoiceList (@unused INTEGER = NULL)
RETURNS @InvoiceTable TABLE
(
	SupportContract_ID INTEGER,
	Customer VARCHAR(50),
	ContractNum VARCHAR(20),
	ContractStart DATETIME,
	ContractEnd DATETIME,
	ContractValue DECIMAL(18,2),
	ContractInvoiceDays INTEGER,
	ContractNumberOfPayments INTEGER,
	InvoiceValue DECIMAL(18,2),
	InvoiceDate DATETIME,
	InvoicePeriodStart DATETIME,
	InvoicePeriodEnd DATETIME,
	InvoiceDuration INTEGER,
	PaymentNumber INTEGER,
	PaymentTerms VARCHAR(255),
	AccountMgr VARCHAR(255),
	TASCode VARCHAR(20),
	Description VARCHAR(1024),
	ProductCode VARCHAR(50),
	TAS_ID INTEGER,
	CustomerRef VARCHAR(20),
	InvoicedToTAS BIT	
)
AS
BEGIN 

	DECLARE @cont_SupportContract_ID AS INTEGER
	DECLARE @cont_Customer AS VARCHAR(50)
	DECLARE @cont_ContractNum AS VARCHAR(20)
	DECLARE @cont_StartDate AS DATETIME
	DECLARE @cont_EndDate AS DATETIME
	DECLARE @cont_Price AS DECIMAL(18,2)
	DECLARE @cont_InvoiceDays AS INTEGER
	DECLARE @cont_NumberOfPayments AS INTEGER
	DECLARE @cont_PaymentTerms AS VARCHAR(255)
	DECLARE @cont_AccountMgr AS VARCHAR(255)
	DECLARE @cont_TASCode AS VARCHAR(20)
	DECLARE @cont_Description AS VARCHAR(1024)
	DECLARE @cont_ProductCode AS VARCHAR(50)
	DECLARE @cont_TAS_ID as INTEGER
	DECLARE @cont_CustomerRef AS VARCHAR(20)
	DECLARE @cont_Invoice_ID AS INTEGER
	DECLARE @cont_InvoicedToTAS AS BIT
	
	DECLARE @temp_ContMonths AS INTEGER
	DECLARE @temp_MonthsBetweenPayments AS INTEGER
	DECLARE @temp_InvoicePeriodStart AS DATETIME
	DECLARE @temp_InvoicePeriodEnd AS DATETIME
	DECLARE @temp_InvoiceDate AS DATETIME
	DECLARE @loop_var AS INTEGER
	
	----------------------------------------------------------------------------------------------------------------------------
	-- Get a list of contracts and open a cursor for the result set

	-- NP Changing Price to ContractValue
	-- NP Changing PaymentPeriod_ID to NoOfPayments
	-- NP Changing TASCode to TAS_CODE
	DECLARE contract_cur CURSOR FOR
		
		SELECT 
			SupportContract_ID, 
			Customer, 
			ContractNumber, 
			StartDate, 
			EndDate, 
			ContractValue, 
			InvoiceDays, 
			NoOfPayments, 
			PaymentTerms, 
			AccountMgr, 
			TAS_CODE,
			Description,
			ProductCode,
			TAS_ID,
			CustomerRef
		FROM V_Contracts 
	
	OPEN contract_cur
	FETCH NEXT FROM contract_cur INTO 
					@cont_SupportContract_ID,
					@cont_Customer, 
					@cont_ContractNum, 
					@cont_StartDate, 
					@cont_EndDate, 
					@cont_Price,
					@cont_InvoiceDays, 
					@cont_NumberOfPayments, 
					@cont_PaymentTerms, 
					@cont_AccountMgr, 
					@cont_TASCode,
					@cont_Description,
					@cont_ProductCode,
					@cont_TAS_ID,
					@cont_CustomerRef
	
	WHILE (@@FETCH_STATUS = 0)
	BEGIN
		-- Check that a charge will be made
		IF @cont_NumberOfPayments > 0
		BEGIN
			
			-- Determine the duration, in months, rounded down of the contract (rounded down is ok since all contracts run a whole number of months)
			SET @temp_ContMonths = DATEDIFF(month, @cont_StartDate, DATEADD(day, 1, @cont_EndDate))

			-- Determine how often they have to pay
			SET @temp_MonthsBetweenPayments = @temp_ContMonths / @cont_NumberOfPayments
	
			-- for each payment, add a row to our output table
			SET @loop_var = 0
			WHILE (@loop_var < @cont_NumberOfPayments)
			BEGIN
				
				SET @temp_InvoicePeriodStart = DATEADD(Month, @loop_var * @temp_MonthsBetweenPayments, @cont_StartDate)
				SET @temp_InvoicePeriodEnd = DATEADD(Month, @temp_MonthsBetweenPayments, @temp_InvoicePeriodStart)
				SET @temp_InvoiceDate = DATEADD(Day, @cont_InvoiceDays * -1, @temp_InvoicePeriodStart)

				-- NP Checking to see if record as being invoiced to TAS		
				SET @cont_InvoicedToTAS = 0
				SET @cont_Invoice_ID =0
				DECLARE InvoicedToTAS_cur CURSOR FOR

					SELECT
						Invoice_ID
					FROM 
						TB_Invoice
					WHERE
						SupportContract_ID = @cont_SupportContract_ID AND
						PaymentNumber = @loop_var +1
				OPEN InvoicedToTAS_cur
				FETCH NEXT FROM InvoicedToTAS_cur INTO 
						@cont_Invoice_ID
				IF @cont_Invoice_ID>0
				BEGIN
					SET @cont_InvoicedToTAS = 1
				END

				-- Close the cursor	
				CLOSE InvoicedToTAS_cur
				DEALLOCATE InvoicedToTAS_cur	
				-- NP End of checking process				


				INSERT INTO @InvoiceTable VALUES
							(
								@cont_SupportContract_ID, 
								@cont_Customer, 
								@cont_ContractNum, 
								@cont_StartDate, 
								@cont_EndDate, 
								@cont_Price, 
								@cont_InvoiceDays, 
								@cont_NumberOfPayments,
								@cont_Price / @cont_NumberOfPayments, 
								@temp_InvoiceDate, 
								@temp_InvoicePeriodStart, 
								@temp_InvoicePeriodEnd,
								@temp_MonthsBetweenPayments, 
								@loop_var + 1, 
								@cont_PaymentTerms, 
								@cont_AccountMgr, 
								@cont_TASCode, 
								@cont_Description,
								@cont_ProductCode,
								@cont_TAS_ID,
								@cont_CustomerRef,
								@cont_InvoicedToTAS
							)
				
				SET @loop_var = @loop_var + 1
			END		
		END	
	
		FETCH NEXT FROM contract_cur INTO 
						@cont_SupportContract_ID, 
						@cont_Customer, 
						@cont_ContractNum, 
						@cont_StartDate, 
						@cont_EndDate, 
						@cont_Price,
						@cont_InvoiceDays, 
						@cont_NumberOfPayments, 
						@cont_PaymentTerms, 
						@cont_AccountMgr, 
						@cont_TASCode,
						@cont_Description,
						@cont_ProductCode,
						@cont_TAS_ID,
						@cont_CustomerRef
	END

	-- Close the cursor	
	CLOSE contract_cur
	DEALLOCATE contract_cur
	
	RETURN

END





Thanks,

Adam
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: problem with function - 9/13/2006 14:17:10   
How are you scripting the DRW to call this?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to adam2804)
adam2804

 

Posts: 34
Joined: 6/6/2006
Status: offline

 
RE: problem with function - 9/13/2006 14:33:55   
I've tried allsorts of ways,

SELECT TOP 100 PERCENT * FROM FN_InvoiceList

SELECT * FROM FN_InvoiceList

With & without 'WHERE' conditions and I've tried putting it inside a 'VIEW' and calling that.

Is there a particular way in which to call a function within FrontPage?


(in reply to Spooky)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: problem with function - 9/13/2006 20:57:11   
So, it is actually working but not returning the expected number of records?
When paging only? or also when displaying all?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to adam2804)
adam2804

 

Posts: 34
Joined: 6/6/2006
Status: offline

 
RE: problem with function - 9/14/2006 4:07:47   
Yes it does work to some extent.

However it's not displaying the correct number of records when using paging as well as when I display all. I thought there could be some problem with FP parsing the function, maybe the FETCH statement not working properly.

(in reply to adam2804)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> ASP and Database >> problem with function
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts