SSRS and SQL NTILE won't accept parameter? - sql

I am using SSRS Report Builder 3.0 and I have put together a report, part of which uses a query that pulls in data and separates it into different summary rows using the NTILE() function in SQL. That's all working fine and dandy, but boss now wants me to add a parameter to decide whether the report should pull quartiles, quintiles, deciles, etc. and so I figured I would just create a parameter to pass an integer to the NTILE(#ntiles) function, and that would be a piece of cake.
Problem is, I've created my parameter, it is an INT and passes a value like (2,3,4,5,6,10) and linked it to my query in Report Builder, but when I save the query with NTILE(#ntiles) (I named my parameter #ntiles) it throws an error:
The function 'ntile' takes only a positive int or bigint expression as its input.
The funny thing is, the report will still run, and correctly as if the parameter works, but I have no idea why it's throwing this error and pretending like it's not going to work. Google didn't really turn anything up on this issue; is it a bug with Report Builder 3.0 or am I doing something wrong? How can I make the error go away? Thanks.
EDIT: Trying NTILE(CAST(#ntiles as INT)) threw the same error, and then broke the query so that the report would not run. Weirdly enough, just changing it back to NTILE(#ntiles) left it still broken; workaround was to change it to a real INT like NTILE(4), reload the query, then go back and change it to NTILE(#ntiles). It still throws the error when you save it, but it does not prevent the report from running with that workaround.

Related

Weird Access Query Problem - Running Saved Access Query Can't Find Fields. Is this a Buffer problem?

Version 1 of the problem:
I create a simple (or complex) SQL query that works and save it, and then come back to it another day and try to run it. I get a message that it cannot find a field that is clearly in the table. If I copy the exact same query into a blank SQL window it works fine.
Version 2 of the problem:
Another version of this type of problem is when I write a query, run it a bunch of times, and then modify it in the same window, it sometimes (=quite often but not always) can't find a field that is clearly in the table. Again, copying the same query into a new window works just fine.
An example:
SELECT *
FROM table1
WHERE code1='xxx' and code2= 'yyy'
ORDER BY sortfield
I get the window saying 'Enter Parameter value for field Query1.sortfield' .
sortfield is in the table and copying this query to a new window works fine.
And to be clear, the query worked fine when first written.
Seems like Access is not properly clearing the buffer somehow.
I have Access 2010 and this happens very frequently, like maybe but not quite always, and seems to be getting worse. I have always had version 2 of the problem to some extent but version 1 is relatively new.
Does anyone have an idea of how to fix this?
Help is much appreciated!

Invalid procedure call when running SQL statement (Max function with parameter)

So this is my third question in so many hours. Thanks again to everyone who has taken the time to help me through my SQL ordeal. I think this might be my last tango for the night, so here goes:
After taking some very good advice from #Vojtěch Dohnal, I converted one of my queries from a concatenated string to a parameterized SQL query here:
PARAMETERS NewPrefix TEXT; SELECT MAX([Suffix]) FROM [SalesTable] WHERE [Prefix] = [NewPrefix];
From what I can tell, this should be the right syntax for creating a parameterized query; the user will define what should go into the NewPrefix field and it will find the appropriate max function based on that. However, whenever I go to execute this query it hits me with the same 'Run-time error '5'; Invalid procedure call' error I've been wrestling with for about 9 hours now haha
I went ahead and tried to test the same query in the Access SQL query window, and I receive an error message there claiming: "This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables".
I'm not sure how to get around this. I don't think the syntax is wrong, but I can't find anything to compare it to on the Internet. I've used the debugger to step through and it looks like all of the values and variables and fields are populated correctly, but when it gets to the execute command it crashes with the same singularly unhelpful error message.
Thanks again for anyone who can help.
So it looks like the main problem that I was running into was that the "Prefix" field was actually a calculated field in my underlying Access table. For whatever reason, Access doesn't want to work with calculated fields with SQL; when I took out the calculation and just made the Prefix column a regular field, everything seems to work perfectly. I'm not really happy with this but it seems to work and that's what matters. Thanks to everyone who took the time to try and help me with this stuff. Cheers!

SQL Server function returns different results in two different query panes

Got me flummoxed!: I have a function that I call...
SELECT UNIT
FROM POWER_ASSETS.[dbo].[returnbaseload] ('03-12-2015','EUR')
WHERE C_TIC = 'LSE:SOE'
The function "returnbaseload" queries values from a view and does some calcs with the values. Simple. It returns 29 rows.
If I open it up in a new SQL query tab, copy n paste... it returns 533 rows.
If I copy and paste from new tab back to old tab.... 29 rows.
Any ideas? Got me beat.
P.S have also tried putting
Use POWER_ASSETS
GO
just in case there was a duplicate table accidentally created somewhere in the master...
I am worried because I am calling the function eventually from a vb program and am getting the wrong amount of rows from the sql query in vb. That's what got me investigating... the right amount of rows was from the new tab, 533 rows.
There's no way a deterministic select fetches different result sets when using the same parameters. Period.
As comments indicates you must being overloking or missing something.
1 - Be sure both panes are using the same.
[SERVER/INSTANCE].[DATABASE].[SCHEMMA].[TABLE]
it's by far the most common scenario.
It also is valid for function/SP calls. Be sure you are calling the same object and not a different version of it.
2 - Be sure both are using the same user/privileges.
Maybe you are using different connection parameters
.
3 - Be sure there's no implicit convertion messing with your query.
You are using some sort of varchar to date convertion here. Be sure you got the same settings (collation, copy from a unicode to a UTF-8 archive, etc.) in both tabs. Also you can try to query the table using some sort of GETDATE() function instead of dealing with that varchar literal.
4 - Be sure your data is not changing while you query it.
Stop the server and put it in single user. Maybe your data is just being updated.
5 - Be sure there are not any random function in the query.
Sometimes we got funny BL and someone unintented put some rand logic in it.
6 - Be sure you are not just drunk or tired.
Once I and a friend where working for like +20hrs no stop. He got angry with a buggy "dot" in the screen. Turned ou it was a actual bug (a fly) and also tried to get rid of it with the mouse pointer.
Calm down and call a friend to get a look on it.

Coldfusion displays 0E-20 Instead of a Zero

I have developed an RIA for a company's external sales force where they can view relevant information regarding thier customers before a site visit.
The data resides in SQL and is set to default to zero if any of the values are NULL. For example
(SELECT ISNULL(SUM(ISNULL( FMS2.NotDueLCY, 0)), 0) AS NotDueLCY
FROM dbo.FLEX_BalanceOverdue AS FMS2
WHERE
FMS2.ShipToCode LIKE #ShipToCode
AND
FMS2.Customer LIKE #Customer
AND
FMS2.SalesPersonCode LIKE #SalesPerson) AS NotDueLCY
If this query is Executed the data looks correct. This query is in a Stroed Procedure. I then use coldfusion to inoke these SP's
If it is executed using CF the Zero Values appear in the browser window as 0E-20 and susequently this data also appears in Flex as 0E-20
I am a bit stumped as to what is causing this. If any of you have some ideas I would be most grateful
BD :)
Managed to fix this. I had to handle the fact that a NaN was hitting the Flex app when the value of data was a zero and after some thorough checking only a zero. So once that was apparent I applied a label function to the data grid displaying the data. Telling it if a NaN was in the data set display a Zero. Not solved the root of the issue but a tidy work around
It possibly something to do with the way its coming out of your Stored Procedure. If you're using cfstoredprocedure to call your SP you could use cfprocparam to ensure that it is returning the values as the expected datatype.
If you're using CFQuery to call your SP, you'll probably need to CAST your columns on the SP side to make sure that the result is returned as the correct datatype.

query not pulling in select box value, oracle

I am using application builder and setting up select boxes to populate a query that spits out into a report below, I'm having a problem with one populating though, and I can't immediatly see why;
Here's how I'm referencing;
AND CINEMA.LOCATION = :pticketstown
this works fine and pulls in the choice from the select box which is popluated from a query on the cinema table, however when I try and do the same thing for another table, try and pull in a film title from a select box choice - it doesnt seem to work, the rport says no output.
Im setting up the select box the same way, and its pulling in the films, but when as soon as I reference it in the sql report, the ouptut is empty.
FILM.FILM_TITLE = :pfilm
Has nayone any thoughts on why it would fail on something that uses the same method ? is it a case that the value isn't bieng passed across? I'm a little stumped if that's the case as I set it up the same way as the working one.
Thanks for looking
I assume from the sound of it you are using application express? Have you turned on debugging to see exactly what is being passed? It might be encoding the spaces or something.
It seems strange that the two, seemingly similar queries would behave differently. Do you have access to the actual sql produced? If so, i would try running that against your db direct through the command line or sql developer if you have it.