what kinda of SQL is it? TODATE(), TOCHAR(), isdateformat() - sql

I am working on a aggregator and it contain build in functions which are I am not familiar with. Few are these I listed here, does anyone know what SQL format is it?
TODATE(string, in_format[, out_format])
ISDATEFORMAT(value[,date_format])
TOCHAR(numeric_value)
Also, here is how I use it, it does accepting my syntax, but it didn't return correct value.
count(where text_column != TODATE('date_format','YYYY-MM-DD', 'yyyymm'))

for TODATE(string, in_format[, out_format])you can use TODATE('20171114','YYYYMMDD')
for ISDATEFORMAT(value[,date_format]) ISDATEFORMAT("2017-06-15", "%M %d %Y")
and tochar function converts a number or date to a string. e.g
TO_CHAR(1210.73, '9,999.99')
Result: ' 1,210.73'

Finally I found out line of code that works:
sum(DECODE(text_column, DATETOCHAR('date_column','yyyy-mm-dd','yyyymm'),0,1))
So add on top of my original question. What type of SQL is function 'Datatochar'!?

Related

SSRS if field value in list

I've looked through a number of tutorials and asks, and haven't found a working solution to my problem.
Suppose my dataset has two columns: sort_order and field_value. sort_order is an integer and field_value is a numerical (10,2).
I want to format some rows as #,#0 and others as #,#0.00.
Normally I would just do
iif( fields!sort_order.value = 1 or fields!sort_order.value = 23 or .....
unfortunately, the list is fairly long.
I'd like to do the equivalent of if fields!sort_order.value in (1,2,21,63,78,...) then...)
As recommended in another post, I tried the following (if sort in list, then just output a 0, else a 1. this is just to test the functionality of the IN operator):
=iif( fields!sort_order.Value IN split("1,2,3,4,5,6,8,10,11,15,16,17,18,19,20,21,26,30,31,33,34,36,37,38,41,42,44,45,46,49,50,52,53,54,57,58,59,62,63,64,67,68,70,71,75,76,77,80,81,82,92,98,99,113,115,116,120,122,123,127,130,134,136,137,143,144,146,147,148,149,154,155,156,157,162,163,164,165,170,171,172,173,183,184,185,186,192,193,194,195,201,202,203,204,210,211,212,213,263",","),0,1)
However, it doesn't look like the SSRS expression editor wants to accept the "IN" operator. Which is strange, because all the examples I've found that solve this problem use the IN operator.
Any advice?
Try using IndexOf function:
=IIF(Array.IndexOf(split("1,2,3,4,...",","),fields!sort_order.Value)>-1,0,1)
Note all values must be inside quotations.
Consider the recommendation of #Jakub, I recommend this solution if
your are feeding your report via SP and you can't touch it.
Let me know if this helps.

Specify scale in a ABS function?

Is it possible to specify scale in a ABS function from a decimal ?
= ABS(([Accounting].salary+ABS([Accounting].expenses))/2)
As of right now everything works correctly but there is a problem with results when the number has only 1 number after the decimal point:
100.12 - All ok
230.1 - Not ok, it should be 230.10
I want the outcome to always have two numbers after the decimal point.
The query has to work on both MS SQL Server and Oracle. I can specify the query for each db manually.
To me, this is more a user interface issue than a SQL issue.
230.1 - Not ok, it should be 230.10
Seriously, that's both the same number.
In Oracle you can convert a number into a string in order to present it to an end user.
select to_char(234.1,'$9,999.99') from dual
$234.10
Have a look at format models in the Oracle documentation.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm
Just change code:
= ABS(([Accounting].salary+ABS([Accounting].expenses))/2)
By the following:
= CAST(ABS(([Accounting].salary+ABS([Accounting].expenses))/2) AS DECIMAL(18 /*set your format here instead of 18*/,2))
I've just checked it in code:
SELECT CAST(230.1 AS DECIMAL(18 /*set your format here instead of 18*/, 2))
And all works fine
In fact, it's just a question of representation of your numbers in the UI for the user. You can convert your number to the string with using to_char () with the format specified. But it is better to define the output format on the front-end

Excel Concatenate month

I am trying to take the following value and making it into a date format of dd-MMM-yy
For example: 110412 turns into 04-NOV-12
My formula as of right now is:
(CONCATENATE(MID(E14,3,2),"-",(TEXT(LEFT(E14,2),"MMM")),"-",RIGHT(E14,2)))
It is giving me 04-Jan-12.
Please note that I would like the month to be in all caps.
Try using the "UPPER(foo)" function as a wrapper to make the result all caps.
UPPER((CONCATENATE(MID(E14,3,2),"-",(TEXT(LEFT(E14,2),"MMM")),"-",RIGHT(E14,2))))
or better still:
=MID(E14,3,2)&"-"&UPPER(TEXT(DATE(MID(E14,5,2),MID(E14,1,2),MID(E14,3,2)),"MMM"))&"-"&RIGHT(E14,2)

Inequality in Qlikview set expressions

Example from Qlikview help:
sum( {$<Year = {“>1978<2004”}>} Sales )
I try this code, but it did't works
Count( {$<Damages.DamageDate = {">Min(OtherDate)"}>} Damages.Id)
Looks like qlikview did't support dates in inequalities.
Any way if anyowne know how to do things like this please help.
As I remember, you must use a dollar-sign expansion within the set expression. Look up "Set Modifiers with Dollar-Sign Expansions" in the manual. The Min function will then be evaluated and so the set expression should work.
It will look sg like this:
Count( {$<Damages.DamageDate = {">$(=Min(OtherDate))"}>} Damages.Id)
Or perhaps
Count( {$<Damages.DamageDate = {">$(#=Min(OtherDate))"}>} Damages.Id)
I'd use
// Reopen or share this result by using the following Url:
// http://tools.qlikblog.at/SetAnalysisWizard/?sa=J0LC
Count({$<[Damages.DamageDate]={">$(=Min(OtherDate))"}>}[Damages.Id])
Note: I think you should square brackets for qualified field names like "Damages.DamageDate".
You can use the Set Analysis Wizard to change the expression.
Hope this helps!
Regards
Stefan
Another posibility to your question is create a variable for example: vMinDate = Min(OtherDate)
And then you can use your variable in the expression like this:
Count( {$<Damages.DamageDate = {'$(vMinDate)'}>} Damages.Id)
I not find the way how to calculate what I need in qlikview, but I workaround it by make all calculation in sql query.
UPDATE:
Also combination of count and if may be helpful. And don't forget place user selected values into document variables before use it in expressions

Reporting Services - handling an empty date?

Hey, I have a report parameter which looks like this: 01.01.2009 00:00:00
Its a date (as string), as you might have guessed :). The problem is, this param can be an empty string as well. So I tried those expressions:
=IIf(IsDate(Parameters!DateTo.Value), CDate(Parameters!DateTo.Value), "")
=IIf(Len(Parameters!DateTo.Value) > 0, CDate(Parameters!DateTo.Value), "")
Both dont work and the value for the textfield where I print the expressions result is always #Error. As soon as I remove the CDate stuff, it works, but I have to use it. IS there another way to achieve that? What I want is to display nothing if its not a date or the date (format dd.mm.yyyy) if its a date.
Ideas?
Thanks :)
All arguments to the IIf are evaluated, which results in your error, since the CDate will fail for an empty string.
You can get around this by just writting a function along these lines, using a standard if statement:
Function FormatDate(ByVal s As String) As String
If (s <> "") Then
Return CDate(s).ToString()
Else
Return ""
End If
End Function
Then call it with: =Code.FormatDate(Parameters!DateTo.Value)
First, fix your database to properly store dates rather than doing these workarounds. You probably have bad data in there as well (Feb 30 2010 for example or my favorite, ASAP). Truly there is no excuse for not fixing this at the database level where it needs to be fixed except if this is vendor provided software that you can't change (I would yell at them though, well notify them really, and ask them to fix their data model or go to a new product designed by someone who knows what they are doing. A vendor who can't use dates properly is likely to have software that is very poor all around).
In the query that you use to select the infomation, have you considered just converting all non-dates to null?