select case
when sale not in TO_date(sale,'MMYY') then 'N'
else sale
end test
from daily sales
I would like to see if the data in the column meets the following criteria using the above select. I am receiving the following error:
LITERAL DOES NOT MATCH FORMAT STRING
small data set
0109
0106
0409
column is a varchar
to_date('0109', 'mmyy') is correct, it will return 01-01-2009 00:00:00 AM (in one possible format). So the problem is likely in the column - you may have one or more value(s) that are not, in fact, four digits. You need to do some troubleshooting.
Something I would try:
select max(length(sale)) as max_len, min(length(sale)) as min_len from table_name
(daily sales cannot be a table name - table names don't have spaces in them)
Related
I have brought a table from an Authority database into Excel via power query OBDC type, that includes fields like:
Date - various
Comments - mem_txt
Sequence - seq_num
The Comments field has a length restriction, and if a longer string is entered, it returns multiple rows with the Comments field being chopped into suitable lengths and the order returned in the Sequence field as per extract below. All other parts of the records are the same.
I want to collapse the rows based and concatenate the various Comments into a single entry. There is a date/time column just outside of the screen shot above that can be used to group the rows by (it is the same for the set of rows, but unique across the data set).
For example:
I did try bring the data in by a query connection, using the GROUP_CONCAT(Comments SEPARATOR ', ') and GROUP BY date, but that command isn't available in Microsoft Query.
Assuming the date/time column you refer to is named date_time, the M code would be:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
#"Grouped Rows" = Table.Group(
Source,
{"date_time"},
{{"NewCol", each Text.Combine([mem_text])}}
)
in
#"Grouped Rows"
Amend the Source line as required.
I have one table with rows and each row has a column that contains a field name (say raw1 - 'Number001', raw2-'ShortChar003', etc). In order for me to get that value of these fields I have to use a second table; this table has 1 raw with many columns (number001, Number002, ShortChar003, etc).
How can I extract the value?
Good Question..You can use lookup function
=Lookup(Fields!CityColumn.Value, Fields!CityColumn.Value, Fields!CountColumn.Value, "Dataset1")
Or you might have to use string functions..ex LEFT, Substring, Right same like SQL.If possible pls post some data of both tables, I will explain in detail
I'm trying to find the correct Oracle format mask to display numbers on an Apex page in a report in a certain way.
Most of the times these numbers are integers but sometimes these numbers can be floating point numbers.
Let's say I have the following three queries:
Query 1
SELECT TO_CHAR(1, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;
Query 2
SELECT TO_CHAR(0.1, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;
Query 3
SELECT TO_CHAR(0.01, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;
Now I want to use one single format mask which will give me the following results:
Result 1
1
Result 2
0,1
Result 3
0,01
Can anyone provide me with the correct format mask to achieve this?
I've tried a format mask like FM990D999 but it leaves me with a comma trailing the 1 in Query 1.
There are ways to alter your column value in the query while still retaining (some) of the functionality in the report(s). However, having multiple such columns and multiple report you might find there is a lot of overhead for little gain.
Look at this post on the OTN forums: order by date in IR
The issue is much the same: the data in the column represents a date but is actually not a date. This post contains a solution to use in apex < 4.2.
From 4.2 onwards you have a better option called the HTML expression.
Again, linked from OTN: Re: Report formatting/sorting issue
Quoted from linked post, user fac586
Include both variance and abs(variance) in the query:
SELECT
region,
estimate,
actual,
(estimate - actual) AS variance,
ABS(estimate - actual) AS abs_variance,
(CASE
WHEN (estimate - actual)>=0 THEN 'green'
WHEN (estimate - actual)<0 THEN 'red'
ELSE NULL
END) AS variance_color
from
expenses
And the HTML Expression for the "variance" column is:
<span style="color: #VARIANCE_COLOR#; font-weight: bold;">#ABS_VARIANCE#</span>
Hide the #VARIANCE_COLOR# and #ABS_VARIANCE# columns.
#ABS_VARIANCE# is the value shown in the column, but the sort is
performed in the underlying SQL using the original variance value.
This is much like Alex suggested but is a bit more work: formatting in the source, adding an html expression, hiding the other column.
I suppose it depends on how far you want to drive it. Why not just apply the format to the column through its attributes?
Also be aware it is possible to use string substitution syntax in those fields. You could have a couple application items containing format masks, and then reference the correct mask in the format mask field.
Eg:
Application item AI_FORMAT_MASK1 has a value FM9990D00.
In the format mask field you can then use &AI_FORMAT_MASK1.
I have sql tables being read in R with the following code
library(RSQLite)
setwd("C:/Users/Cat/Downloads")
drv = dbDriver("SQLite")
# Use the driver to connect to a particular sqlite database file
con = dbConnect(drv, "cartype")
dbListTables(con)
And there are columns named as ID and credit in a table Sale. Some of the credit is missing and I can select them with the following code.
wow = dbGetQuery(con, 'SELECT DISTINCT ID FROM Sale WHERE
credit IS NOT \"NA\";')
Question is how can I select ID with Date is NA? I tried the code
wow = dbGetQuery(con, 'SELECT DISTINCT ID FROM Sale WHERE
credit IS \"NA\";')
OR
wow = dbGetQuery(con, 'SELECT DISTINCT ID FROM Sale WHERE
credit == \"NA\";')
The codes work but giving a incorrect result that there's 0 result matching the condition, while it should have more than 100 IDs with NA credit.
Can anyone help me out, and show me how can I get IDs with NA credit?
Thanks !
I think you're coming up against a mis-aprehension about how missings are stored in databases. These are usually stored as NULLs as opposed to NA.
Your first statement works because it is comparing a column of some type (e.g. date, int, varchar) against a string ("NA") and this will exclude NULLs because a string comparison (whether implicit or explicit) will always exclude missings and since all your dates will be different to "NA" it will return all non-missing records.
The reason why your second and third statements go onto return 0 records is because it is again doing a string comparison which will exclude NULLs and also won't find a match.
For SQLite, there is a great page on how NULLs are handled which might help you out with more detail on this topic: http://sqlite.org/nulls.html
I am trying to use Set Analysis in the table below for the column labelled test. I am trying to get sum([Best Dollar]) for the date range specified by the Start and End columns.
This expression returns results, but it's naturally static for each row of the table:
=sum({$<AsAtDate={">=40959 and <=40960"}>} [Best Dollar])/1000
This is what I want to have but it returns 0:
=Sum({$<AsAtDate={">=(num(floor(BroadcastWeekStart2))) and <=(num(floor(BroadcastWeekStart2)))+6"}>} [Best Dollar])/1000
To obtain unique start date serial numbers for each line for the start column (BroadcastWeekStart2) I use the following expression:
=(num(floor(BroadcastWeekStart2)))
How can I specify that the values or calculations used for the start and end columns are used in Set Analysis for the field above?
There is at least one information missing in your question.
Do you want to select on fixed values or should the sum depend on the current time?
For the static version something like
=sum( {$<BroadcastWeekStart2={"40959"}, BroadcastWeekStart2={"<=40960"}>} [Best Dollar])/1000
should work. (Assuming that BroadcastWeekStart2 contains these kind of values.)
Let me show you an example how I calculate values for the current week:
='Count: ' & count({$<start_week={"$(=WeekStart(Today()))"}>} Games)
where the start_week is set in the load script by:
WeekStart(date#(#4, 'YYYYMMDD')) as start_week,