Based on below formula, [Yesterday] variable is holding last date value but at run time it is not returning any result.
What should be the right syntax here?
=Sum([Total Amount]) Where ([Booking Date] = [Yesterday])
Having all the code would be helpful, but with the info we have I would recommend removing the brackets and leaving the select like this:
where "BookingDate" = Yesterday;
Related
So I'm working on editing some SQL code and I've just began learning it. I'm trying to fix an update query so it updates a table's value5 column with a corresponding database value. The value type from the database is a number, which I want to convert to a date and place into my table. The database number is in yyyymmdd format so I've been trying to use datefromparts() which doesn't work. Anyone have any ideas?
UPDATE tbl INNER JOIN dB ON
(dB.value1= tbl.value1 OR
dB.value2 =tbl.value2 ) AND
(LEFT(dB.value3 ,5)=tbl.value3 ) AND
(dB.value4 =tbl.value4 )
SET tbl.value5 = DateFromParts(Left(dB.value5,4),Mid(dB.value5,5,2),Right(dB.value5,2))
WHERE tblInvoice.value5 IS NULL;
The current program uses the code
"SET tbl.value5 = dB.value5"
instead (it runs perfectly fine) and I am having another issue with testing the conversion SQL code (datefromparts()). Because I am converting from numbers to time/date, I have to go into the design view of the target table and change the input data type of the value5 column from numbers to time/date. When I run the query with the conversion SQL code, the query stalls for a bit and no values get updated, leaving me with just a blank value5 column. If I now want to fill in the original number values, I change the SQL code back into its original "SET tbl.value5 = dB.value5", change the input data type from time/date to numbers, and rerun the program. The query stalls and no values are updated, and I am again left with blank columns, even though the same code left me with the corrected update values before the modifications to the SQL and table input Data types. I come from a VBA background and I'm just really confused with how this is working. Any tips would be appreciated, thanks!
Have you tried with substring instead?
SELECT DATEFROMPARTS ( left('20101231',4), substring('20101231',5,2), right('20101231',2) ) AS Result;
MS Access (and MS Jet too) have no DateFromParts function. Using DateSerial instead.
SET tbl.value5 = DateSerial(Left(dB.value5, 4), Mid(dB.value5, 5, 2), Right(dB.value5, 2))
It's not clear if you work with T-SQL or Access SQL. In Access, you can use Format:
SET tbl.value5 = CDate(Format(dB.value5, "####\/##\/##"))
In T-SQL you could use a similar method.
I am attempting to set a conditional format for one of the fields in my SSRS report. Basic formatting which would change font color. This is my original expression in report builder:
=IIf(Fields!delta.Value <
IIf("ex1"=Fields!ID_name.Value
,0.95
,IIf("ex2"=Fields!ID_name.Value
,0.988
,0
)
)
,"Red"
,"Black")
However, I have to do this for over a 100 different "ID_name" values which all share common "delta" values.
I was wondering if there is something similar to the IN clause in SQL that would allow me to paste all the "ID_name" values inside ('','','') format so it would be much easier? Something like this:
=IIf(Fields!delta.Value <
IIF(Fields!ID_name.Value IN ('ex1','ex2','ex3','...')
,0.95
,IIF(Fields!ID_name.Value IN ('ex4','ex5','ex6','...')
,0.988
,0
)
)
,"Red"
,"Black")
I tried the IIf(InStr() method but my "ID_name" share similar names with others that have different delta values so a contains clause would not work.
Is this possible? Appreciate any and all input! Thanks!!
You can do this but you'll need to wrap your text values in some kind of delimiter that won;t appear in your values to check like [ex1][ex2] etc..
You can use the contains method but it needs to be opposite way you would do a typical IN statement. Something like this..
IIF ("[ex1][ex2][ex3]".Contains("[" & Fields!ID_name.Value & "]"), 0.95, FalseBitHere)
Of course you can just use a comma or whatever you like as long as it wont; appear in your actual values to test.
I have a Pentaho CDE project in development and i wanted to display a chart wich depends on several parameters (like month, year, precise date, country, etc). But when i want to "add" another parameter to my query, it doesn't work anymore... So i'm sure i'm doing something wrong but what ? Please take a look for the parameter month for example :
Select_months_query : (this is for my checkbox)
SELECT
"All" AS MONTH(TransactionDate)
UNION
SELECT DISTINCT MONTH(TransactionDate) FROM order ORDER BY MONTH(TransactionDate);
Select_barchart_query : (this is for my chart, don't mind the other tables)
SELECT pginit.Family, SUM(order.AmountEUR) AS SALES
FROM pginit INNER JOIN statg ON pginit.PG = statg.PGInit INNER JOIN order ON statg.StatGroup = order.StatGroup
WHERE (MONTH(order.TransactionDate) IN (${month}) OR "All" IN (${month}) OR ${month} IS NULL) AND
/*/* Apply the same pattern for another parameter (like year for example) *\*\
GROUP BY pginit.Family
ORDER BY SALES;
(Here, ${month} is a parameter in CDE)
Any ideas on how to do it ?
I read something there that said to use CASE clauses... But how ?
http://forums.pentaho.com/showthread.php?136969-Parametrized-SQL-clause-in-CDE&highlight=dynamic
Thank you for your help !
Try simplifying that query until it runs and returns something and work from there.
Here are some things I would look into as possible causes:
I think you need single quotes around ${parameter} expressions if they're strings;
"All" should probably be 'All' (single quotes instead of double quotes);
Avoid multi-line comments. I don't think you can have multi-line comments in CDE SQL queries, although -- for single line comments usually works.
Be careful with multi-valued parameters; they are passed as arrays, which CDA will convert into comma separated lists. Try with a single valued parameter, using = instead of IN.
I am using report builder and I have created an IIF statement on a calculated field I have created (called Tolerance)
The field of "Tolerance" is returning a difference in time between two other fields in the format of 00:00:00.
My IIF statement is as follows:
=IIF(Fields!Tolerance.Value < = "-00:10:00", "Passed","Failed")
This is running OK in the report but the results are all #Error.
You have an space between < and =. This space is not allowed, as these are not two different operators, but a single <= operator:
=IIF(Fields!Tolerance.Value <= "-00:10:00", "Passed","Failed")
Is your field Tolerance.Value a number?
Value "-00:10:00" is a string.
Try
=IIF(CSTR(Fields!Tolerance.Value) <= "-00:10:00", "Passed","Failed")
It would be helpful if you would provide samples of your Tolerance.Value values. This solution might only fix the #Error in your resulting report, but not be what you want in case Tolerance.Value should be formatted to similar format with your "-00:10:00" value.
Heres the query which is giving the issue
select * from
(select user,logdate,[in time],[out time],[worked time] from tmp_phys_table) as sr1
PIVOT
(SUM([worked time]) FOR [LOGDATE] IN ([1])) AS TMPQ
I am unable to understand what the issue is. I was doing pivot as I wanted to make the rows into columns.
I want the output in the below format. The image is the one which I had created in excel for the visualization of data for my report purposes,the same I want in sql,but I am not getting the idea for how to go about the dates hence the query which I had written and which is giving the above error
No column was specified for column 1 of 'sr1' for pivot function
I think your issue is the use of a reserved word in you field name; User is a reserved word, you will need to alias it though I would highly recommend changing the field name.
SELECT *
from (SELECT user As Usr,logdate,[in time],[out time],[worked time]
from tmp_phys_table) as sr1
PIVOT (SUM([worked time]) FOR [LOGDATE] IN (1)) AS TMPQ
NOTE: I have not tested this, I am just going off what stands out as the issue
I would also strongly suggest changing some of your other columns so they do not have spaces in, as you have correctly typed they require square brackets, which will become frustrating over time.