Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Cross apply question

Author  Topic 

bcanonica
Starting Member

35 Posts

Posted - 2009-08-21 : 12:15:56
So I guess I can't do this? Reference the First table functions values in the cross apply's table functions parameters (A.agr_active_days)? I read a thread about the compatibility level of my database and how upgrading from 80 to 90 might allow me to execute this query, but since I am using a linked server I don't have that option. Any other ideas or a better way of doing this?

Function dbo.GetAllAgreementAmounts returns all active agreements for a company and how much they are charged daily. Also returns the value in question agr_active_days, which I need is the number of days the agreement was active in a date range.

Function dbo.xf_TableNumberRange returns a basic table with number values.

I receive the following error: Msg 102, Level 15, State 1, Line 21
Incorrect syntax near 'A'.


Declare @start_date datetime, @end_date datetime

SET @start_date = '6/1/2009'
SET @end_date = '6/30/2009'

SELECT
B.[Date]
, MONTH(B.[Date]) AS [Month]
, YEAR(B.Date) AS [Year]
, A.[agr_amount_daily]
, A.[company]
FROM dbo.GetAllAgreementAmounts(@start_date, @end_date) AS A
CROSS APPLY
(
SELECT [Date] = dateadd(dd,number-1, A.agr_active_date_start)
-- Value that is giving the issue below A.agr_active_days
FROM dbo.xf_TableNumberRange(1, A.agr_active_days)
) AS B

bcanonica
Starting Member

35 Posts

Posted - 2009-08-22 : 09:46:33
OK I figured it out I created a new database with compatibility level 90 and call the table valued functions for my other database in that database.

Inspiration for resolution below.

http://www.sqlservercentral.com/articles/cross+apply/67182/


Hope this helps someone else out.
Go to Top of Page
   

- Advertisement -