I have to define a lookup like this in my *.rdl file;
=IIF(Parameters!CompanyId.Value<>67,IIF(LAST(Fields!GallonsPumped.Value)>0, 0, " "),
Lookup(Fields!TankDateCombo.Value, Fields!TankDateCombo.Value,IIF(LAST(Fields!GallonsPumped.Value)>0, 0, " "),"Dataset2"))
But I get error saying that I canot use functions in LOOKUp. How can I do this in correctway>
This is the correct syntax (match Table2 on Table1):
=Lookup(Fields!KeyTable1.Value, Fields!KeyTable2.Value, Fields!DisplayValueTable2, "Table2DatasetName")
Lookup() just matches a 1:1 relationship, if you have a 1:n you need to use LookupSet(). If Lookup() doesnt find a match it returns Nothing.
I have fixed like this(surrounding lookup with function name)
eg:
=IIF(Parameters!CompanyId.Value<>67, IIF(LAST(Fields!GallonsPumped.Value)>0, 0, " "),
IIF(LAST(Lookup(Fields!TankDateCombo.Value, Fields!TankDateCombo.Value,Fields!GallonsPumped.Value,"Dataset2"))>0, 0, " ")
)
Related
In SSIS, how would you parse the values between the " " in this example:
KeyFieldForRecord:"ORD101300"}
So that the derived column value only returns: ORD101300 ?
I think the fact that the source wraps what I need in "" will make it challenging to use any of the SSIS string functions
You can simply use REPLACE in your derived column:
REPLACE(KeyFieldForRecord, "\"", "")
In my project I am using dsum to query a table to compare years. But I want to render the field as a year for the comparison.
Public Function GetValue(whatyear) As Long
GetValue = DSum("Modification", "Accounting Totals", "Format([EntryDate],'yyyy') = " & whatyear & " AND [ModType] like *2*")
End Function
I keep getting this error:
Syntax error (missing opeator in query expression
'Format([EntryDate],'yyyy' = 2016 AND [ModType] like *2*"
This is probably an easy one for you VBA Gurus. What do I do?
you need qoutes for the year, and if [ModType] is text, you need qoutes for it as well. in addition, handle null values like this, else if it doesn't find any rows, that will throw another error:
Nz(DSum("Modification", "Accounting Totals", "Format([EntryDate],'yyyy') = '" & whatyear & "' AND [ModType] like '*2*' "), 0)
if [ModType] is a numeric value, then the like operator is not going to work, you need to use another operator such as these: =, >=, <=, BETWEEN
Got it - I had to remove the As Long from the function declaration
If so, you may have zero records and DSum returns Null. Catch that - as O. Gungor showed - with Nz. And get the year as a number:
So:
Public Function GetValue(ByVal whatyear As Integer) As Currency
GetValue = Nz(DSum("Modification", "Accounting Totals", "Year([EntryDate]) = " & whatyear & " AND [ModType] Like '*2*'"), 0)
End Function
At a high-level this sounds trivial, but it turns out I've been scratching my head for a a couple of hours.
Situation:
I have table T, with columns a,b,c,d,e. Column a holds a string, while b,c,d,e each hold a boolean value.
I am allowing a user to perform a kind of search, where I prompt the user to enter values for a,b,c,d,e, and return all the rows where those values all match.
In a perfect world, the user enters all values (lets say a="JavaScript" , b="true", c="false", d="false", e="true") and a resulting query (In Scala, referencing a remote DB running MySQL) might look something like this:
connection.createStatement().executeQuery("SELECT * FROM T
WHERE a = '" + a_input + "'
and b = " + b_input + "
and c = " + c_input + "
and d = " + d_input + "
and e = " + e_input + ";")
Problem:
I give the user the option to 'loosen' the constraints, so it is possible that a_input="" and b_input="", etc... Potentially all fields a,b,c,d,e can be empty ("") If a field is omitted, it should not affect the resulting response. In other words, if c is not entered, the result can contain entries where c is TRUE or FALSE
Question:
How do I write ONE query that covers the situation where potentially all fields can be empty, or just some, or none?
Just build the WHERE dynamically. Instead of always searching for c = 'whatever', only include c in the WHERE if the user supplied a value for it.
you could use
Select *
from table
where a in ('','othervalue','othervalue')
and b in ('','othervalue','morevalues')
and so on.....that is like using an or for each field and it will match even if it's empty
This is tricky because the DB contains booleans but the parms are strings. Are the parms always blank. 'true', or 'false'? If so try
(B_input=''
Or (b_input=''true' and b)
Or (b_input='false' and ((not b)))
While I use proper ORM-mappers for most of my application, there is a few very complicated to implement. That's why I tried to use Literal-SQL.
Now I want to pass a list of values as parameter to that query.
A simplified example of the problem looks as follows:
ids = [1, 2, 3]
session.query('name') \
.from_statement('SELECT name FROM users WHERE id IN(:ids)') \
.params(ids=ids).all()
This doesn't work due to the error:
sqlalchemy.exc.InterfaceError: (InterfaceError) Error binding parameter 2 - probably unsupported type.
So how can I make that work?
So it seems like sqlalchemy doesn't know what to do with the list type in params, though I suspect the error you listed was from another example based on parameter 2 being the problem.
Here is a link that addresses your listed error. For the list issue, you could try something like:
def makeSQLList(myList):
if not myList:
return "()"
newString = "(" + str(myList[0])
for i in range(1,len(myList)):
newString += "," + str(myList[i])
newString += ")"
return newString
ids = [1, 2, 3]
session.query('name') \
.from_statement(text('SELECT name FROM users WHERE id IN ' + makeSQLList(ids))) \
.all()
Or you could extend sqlalchemy to accept whatever type you're having a problem with. Or, try posting your complicated query and maybe the community can help simplify using the ORM-mappers. Hope one of these options helps!
My situation is
I have a parameter, this is a list, allowing multi values. That mean the first record in the list is 'Select All'
When user select All I need to include in my report all records that match with the list plus those that are blank. (My dataset is returning these)
When user select only 1 or a few I want to include only these records. No those that are blank
My problem:
I have a filter in my dataset that evaluate a parameter in a list, but I need to add a conditional filter to include a blank records when the selection will be "Select All"
I tried to use expression but this doesn't work
Filter expression
Fields!NAME.Value in = Parameters!List.Value !!!!!!!!!!!! Work Fine
But I need to change it like as
If Parameters!List.Value = 'Select All' Then
Fields!NAME.Value in = Parameters!List.Value or Fields!NAME.Value = " "
Else
Fields!NAME.Value in = Parameters!List.Value
End
Can you give an advice who can I resolve it please !!!
I'm working in SSRS R2
Thanks!!
This worked for me
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, FALSE)
Operator: =
Value: =IIF(Parameters!pLocation.Value <> " All Locations", Parameters!pLocation.Value, FALSE)
If you use Filter on your Dataset, try this:
Expression: [NAME]
Operator: IN
Value (fx): =Split(Replace(Join(Parameters!List.Value, ","), "Select All", " "), ",")
Try to work along this path. Basically you can reconstruct the multi value items into a string with Join(), and deconstruct it again into array by using Split(); where in between, you can manipulate them, for modifying (e.g. converting "Select All" into " "), adding (imitating "OR"), or removing extra items.
There is an alternative for this.
Add one more item to the paramater dataset values say "Not Available" as Label and value with the null. then there will be no change in the stored procedure and you can retrieve the data.
If the user select the specific item then he will get those values only. If he selects all then he will get the data for the null also with the all the others.
Hope this will help
You can put the logic in just one location if you do it this way.
You filter on the parameter, unless it's all values then the filter always matches.
Just a little cleaner.
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, " All Locations")
Operator: =
Value: =Parameters!pLocation.Value