I have a problem getting a piece of SQL to run.
When I run that in the "Mydbname" database it won't run, however when I run it in the master database it will. When I take of the "[Mydbname].[dbo]." part while in the right database it also gets the error below. No combinations seem to resolve it so far.
The function fnEarningsByStateSitePlanMonthYear is in the Mydbname database with dbo. I can't figure out why SQL Server is seemingly wanting me to run the statement remotely rather than when I'm connected to the actual database the tables and function reside in.
Here is a description of what the function call does.
-- A user will be prompted for a parameter for the following:
-- Start Date 12/31/2005 (example data)
-- End Date 06/30/2006 (example data)
-- SiteID 205 (example data)
-- That data will triger a call to the ReportMonthsYear Table which will return the following:
-- Month, Year, Start date, End date
-- 01, 2006, 01/01/2006, 01/31/2006
-- 02, 2006, 02/01/2006, 02/28/2006
-- 03, 2006, 03/01/2006, 03/31/2006
-- 04, 2006, 04/01/2006, 04/30/2006
-- 05, 2006, 05/01/2006, 05/31/2006
-- 06, 2006, 06/01/2006, 06/30/2006
-- That data will then return the report such that all rows from the monthsyear table that are returned
-- by filtering out before and after the start date will drive a call to the UDF.
--
-- Results
-- 01, 2006, Experience data from function for the period
-- 02, 2006, Experience data from function for the period
-- 03, 2006, Experience data from function for the period
-- 04, 2006, Experience data from function for the period
-- 05, 2006, Experience data from function for the period
-- 06, 2006, Experience data from function for the period
-- =============================================
I want to turn this into a function (that calls this SQL which calls the function) but I can't yet since this keeps popping up. The same error occurs when used in a create function statement as in a native SQL statement.
Any ideas as to how to resolve this?
Code:
SELECT Myfunction.*
FROM [Mydbname].[dbo].monthsyear as m
Cross Apply
[Mydbname].[dbo].[fnEarningsByStateSitePlanMonthYear] (m.[Month],m.[year],205,'W') as [MyFunction]
where m.monthStartDate>='2004-02-01 00:00:00'
and m.[MonthEndDate]<='2005-01-31 23:59:59'
order by [MyFunction].[Name], [MyFunction].[period] asc
When I run that in the "Mydbname" database it won't run, however when I run it in the master database it will. When I take of the "[Mydbname].[dbo]." part while in the right database it also gets the error below. No combinations seem to resolve it so far.
Code:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '.'.
The function fnEarningsByStateSitePlanMonthYear is in the Mydbname database with dbo. I can't figure out why SQL Server is seemingly wanting me to run the statement remotely rather than when I'm connected to the actual database the tables and function reside in.
Here is a description of what the function call does.
-- A user will be prompted for a parameter for the following:
-- Start Date 12/31/2005 (example data)
-- End Date 06/30/2006 (example data)
-- SiteID 205 (example data)
-- That data will triger a call to the ReportMonthsYear Table which will return the following:
-- Month, Year, Start date, End date
-- 01, 2006, 01/01/2006, 01/31/2006
-- 02, 2006, 02/01/2006, 02/28/2006
-- 03, 2006, 03/01/2006, 03/31/2006
-- 04, 2006, 04/01/2006, 04/30/2006
-- 05, 2006, 05/01/2006, 05/31/2006
-- 06, 2006, 06/01/2006, 06/30/2006
-- That data will then return the report such that all rows from the monthsyear table that are returned
-- by filtering out before and after the start date will drive a call to the UDF.
--
-- Results
-- 01, 2006, Experience data from function for the period
-- 02, 2006, Experience data from function for the period
-- 03, 2006, Experience data from function for the period
-- 04, 2006, Experience data from function for the period
-- 05, 2006, Experience data from function for the period
-- 06, 2006, Experience data from function for the period
-- =============================================
I want to turn this into a function (that calls this SQL which calls the function) but I can't yet since this keeps popping up. The same error occurs when used in a create function statement as in a native SQL statement.
Any ideas as to how to resolve this?