I am using report builder with Excel as my data source. I am having a hard time creating a query text in the query designer. I get errors when i try conditional statements of simple group statements.
I have this statement:
SELECT [Flight No],[Full Name],[Date],[Selected Routing 1] AS Routing,
[Selected ETD 1] AS ETD,[Selected ETA 1] AS ETA
FROM [Sheet1$]
this will return these values:
Flight No Full Name Date Routing ETD ETA
1 Peter Hansen 10/1/2012 BNE-MEL 1755 2020
2 Black Hansen 10/2/2012 BNE-MEL 1756 2021+1
Now, i want to create a conditional statement that when ETA has a +1 on its number then the date will add 1. so the table should look like these:
Flight No Full Name Date Routing ETD ETA
1 Peter Hansen 10/1/2012 BNE-MEL 1755 2020
2 Black Hansen 10/3/2012 BNE-MEL 1756 2021+1
I seem to get an error when i try to have an SQL statement like this in the report builder:
SELECT [Flight No],[Full Name],If([Selected ETA 1] LIKE '*+*',[Date]+1,[Date])
AS DATE, [Selected Routing 1] AS Routing,[Selected ETD 1] AS ETD,
[Selected ETA 1] AS ETA
FROM [Sheet1$]
The error says:
An error occurred while executing the query.
ERROR [42000撛] [Microsoft][ODBC Excel Driver] Undefined function 'if' in expression.
(Microsoft SQL Server Report Builder)
ERROR [42000撛] [Microsoft][ODBC Excel Driver] Undefined function 'if' in expression.
(ACEODBC.DLL)
Please give me references if possible. Thanks!
As you can see in the error, the IF function has not been implemented for usage in that context. Your best bet to get this working is by using CASE instead:
Please note that you should avoid using reserved keywords as object names. I’m referring to that columns which you’re aliasing as [DATE]. Date is a data type since SQL Server 2008.
Now that we’ve gone into the best practices direction, I wouldn’t use spaces in object names either. It saves you the hassle of needing to type those square brackets each time when writing a query.
And to finish I would look into a method of importing the Excel sheet in a real database instead of referencing it directly from the report. Even though it works, it’s not really recommended. Any user with access to the file can mess it up so that your report breaks.