Invalid Column name error in SSRS 2005 - sql

I am having an issue with SSRS 2005. I have a case statement that that works fine in other queries and reports, but errors on the latest report for some reason. I don't believe its an issue with the query rather an issue with reporting services. The error I get is "Query execution failed for data set, invalid column name 'Status'.Has anyone else run into this issue? how did you resolve? The code is below just in case
SELECT Task
, Account_Num
, CASE WHEN DATEDIFF(dd,GETDATE(),Due_Date) < 0
THEN 'Overdue'
WHEN DATEDIFF(dd,GETDATE(),Due_Date) < 3
THEN 'Alert'
ELSE 'Okay'
END AS Status
FROM MyDb

Try square brackets around the reserved word [status]

Sometimes this is due to using an alias. Sometimes, one is not allowed to use the alias and must type out the fully-qualified name.
ourDatabase.ourTable.ourColumnName
This may or may not apply to the OP's situation, however. I have not tried it with the Case statement.

Related

Schema reconciliation

I have written a case statement as :
Case when currency=‘Abc’ then outstanding_bal else null end as outstanding _balances_RO
And i my job is failing saying this error messege
Source is ODBC connector , connected to Microsoft SQL server.
Schema reconciliation detected a type mismatch for field outstanding_balances_RO . When moving data from field type varchar(min=0,max=58) into Decimal (15,3)
Since you're already using an expression in the SELECT statement, wrap that expression in a CAST to force it to DECIMAL(15,3) data type.

Quickbook Online API throws Error Parsing query / trying to use CASE statement in SQL query

I am trying to get status based to totalamount field.For that I need to use CASE statement like this :
Select TotalAmt,CASE WHEN 'TotalAmt' = '0' THEN 'Open' ELSE NULL END AS status from Invoice
I have checked the syntax too,it's correct.But still I am getting query Parser error
Intuit's flavor of SQL (which is a very limited, slightly non-SQL-standard dialect of SQL) does not support CASE statements.
You can't do what you're trying to do, as it's unsupported.

SQL COMMAND + CASE Crystal Reports

I am having a an issue with SQL Command and CASE. I am pretty new to Crystal Reports/SQL and I have a basic code that I am playing around with to learn. I want to clean out a field -- that has imported from SQL Server. I just want to do something simple like this:
SELECT "I"."I_TYPE", "Alleg” =
CASE
WHEN "ALLEGs"."ALLEG” LIKE ‘*im*’ THEN ‘Improper’
ELSE ‘UNKNOWN’
END
I get an error that says Database Connector Error:
'42000:[MS][SQL..Incorrect syntax near ' . ' . Databse vender code 102.
Can you even use CASE as an IF THEN statement in the SQL Command. I am aware of SQL expressions, but I am trying to pull data to sql command to prevent performance decrease.
I am not sure about crystal report but your query formation don't look correct. It should be
SELECT I.I_TYPE,
CASE WHEN ALLEGs.ALLEG LIKE '%im%' THEN 'Improper' ELSE 'UNKNOWN' END AS 'Alleg'
Rahul, is correct for direct SQL commands to the server.
However sometimes when running Crystal Reports we use VBA within the report to do some data tuning rather than modifying the raw SQL on the fly.
This leaves the raw SQL a known result (verifiable on the SQL Server) and then modify the output in Crystal to fit the end users filtering requirements.
This is not efficient with large result sets but when the results are smaller (under 50k records) we usually have our team go with simple (post filtering) to reduce design and testing time.
This technique works very well with dynamic filters on the option section.
example: [Record Selection]
if {?Select Sales Person} <> "ENT" then
{R0033___P2A.ProjectionSP} = {?Select Sales Person} and {R0033___P2A.FM} >= 0
else
{R0033___P2A.ProjectionSP} > "" and {R0033___P2A.FM} >= 0
Where {?Select Sales Person} is a user selection filter and {R0033___P2A} is a predefined report view or stored procedure.

how to debug "sql subquery returns more than 1 row" error

We have a huge SQL script involving tens of tables, subqueries, hundreds of attributes. It works perfectly in the test database but returns sql subquery returns more than 1 row error when running in the production database. The script was working perfectly up until now. The problem is, all I get is a one-line error specified above with no clues whatsoever which exact subquery causes the error which makes it near to impossible to debug. The question is, how am I supposed to know which line of the SQL causes the error? Is there any way to "debug" it line by line like you would do it in a programming language?
I am using TOAD with Oracle 11g.
Add print or DBMS_OUTPUT.PUT_LINE commands to your script to print messages. And/or use exception handlers in the script. Possibly add some variables that count or label which statement you are at, and output that in the exception handler.
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm
Once you have found the query that causes the problem, convert it to a similar query with an appropriate group by and having count(*) > 1 so that you can see what data caused the problem. For instance if you have a correlated subquery that looks like:
(select name from names where id=foo.id)
then write a similar query
select id from names group by id having count(*) > 1
to identify the offending data.
If you have multiple subqueries in the query that produces the error, you could temporarily convert the subqueries to use temporary tables and search them all for duplicates.

SQL Statement 'Missing Parameter' Fails On Single Machine

I'm using vb.net, and I've created a sql statement that I use with a OleDBConnection object. When I run my sql (below) the ExecuteReader throws an error (also below). The problem is that it works on the 50+ en-US machines that it's run on, but now I've got my first client in Germany, and it fails on their machine. I set my dev machine to German settings to try to replicate the issue, but it works just fine for me. I copied-over their exact data file and it works on my machine. So seemingly it has to do with it being a non en-US machine?
Here is the SQL statement:
SELECT Val(IIf(IsNumeric([Sequence]), [Sequence], '0')), *
FROM MyTable
ORDER BY SomeOtherField, 1
So in short, I want to order by the sequence column secondarily, but in the event that Sequence isn't numeric I'll just give it a '0' so that it allows the sort to take place based on the dynamic column '1' I am creating/selecting on-the-fly.
Here is the error on the German machine:
Fuer mindestens einen erforderlichen Parameter wurde kein Wert angegeben.
(Roughly translated: For at least one required parameter was not specified value)
Does anyone have any ideas as to what my issue might be? Thanks in advance for any assistance you can provide to me.
-Greg
This is just a guess. But, try replacing the iif() with a case statement:
SELECT (case when IsNumeric([Sequence]) = 1 then [Sequence]
else '0'
end),
mt.*
FROM MyTable mt
ORDER BY SomeOtherField, 1
I suspect that your other systems are using Access, and the German system is using SQL Server. SQL Server does not recognize iif.