JDBC with Microsoft Access - The query return no rows when i use a date in the where clause - date

here is the code i execute...
dc.rs = dc.st.executeQuery("select count(*) from Accounts where date_join = CDATE(25-11-2012)");
It returns 0 rows even though I have 3 accounts in database that will match this.
The format i use when i insert date is
CDATE(day-month-year)
I tried also this format, but still returns nothing..
CDATE('25-November-2012')
I also use that format when i search using dates. But i can't understand why it returns no rows.
i get this error when I try to use the getDate(1) after I query that..
[Microsoft][ODBC Microsoft Access Driver]Restricted data type attribute violation on column number 1 (Expr1000)
Is there any wrong with my where clause?

Change the where clause to data_join = CDATE('25-11-2012')

Related

convert sqlalchemy query written for sqlite to postgres

Flask app made using sqlite and now converting to postgres. I have the following query to gather the daily sales from multiple stores. Then put the sales into a list to use in a chartjs chart.
daily_chart = (
db.session.query(Sales, func.sum(Sales.sales).label("total_sales"))
.filter(Sales.date >= start_week, Sales.date <= end_week)
.group_by(Sales.date)
.order_by(Sales.date)
)
values1 = []
for v in daily_chart:
values1.append(v.total_sales)
I get the following error.
(psycopg2.errors.GroupingError) column "Sales.id" must appear in the GROUP BY clause or be used in an aggregate function
I tried to use with_entities but don't really know sql and could't find an answer that worked with the func statement.
Try removing Sales from the query statement.

Amazon Athena - Cannot convert variable character to date

Using Amazon Athena, I am working with a set of data stored as variable characters and would like to convert them to dates. There are two columns within a table that have dates: (1) action_date and (2) pricing_date.
With action_date, I have been able to successfully convert the original data using the dateparse function with the following query:
SELECT date_parse(s.action_date,'%m/%d/%Y %H:%i:%s') AS dataconverted
FROM "database"."sales" s
With pricing_date, I am having difficulties doing the same despite the data being in the same format. I would assume that the query should be the same. Following is my query:
SELECT date_parse(s.pricing_date,'%m/%d/%Y %H:%i:%s') AS dataconverted
FROM "mydatabase"."sales" s
Following is the error I get in Amazon Athena:
Your query has the following error(s):
[ErrorCategory:USER_ERROR, ErrorCode:INVALID_ARGUMENT], Detail:INVALID_FUNCTION_ARGUMENT: Invalid format: ""
This query ran against the "mydatabase" database, unless qualified by the query.
How I can convert the successfully convert the variable character text into a date format? What could I possibly be missing?
From the error it looks like the pricing_date column sometimes is an empty string. date_parse will throw an error if the input is not on the specified formatat. You can observe this by running SELECT date_parse('', '%m/%d/%Y %H:%i:%s') or SELECT date_parse('asdasd','%m/%d/%Y %H:%i:%s').
You can work around this by adding a guard (e.g. IF(s.pricing_date <> '', date_parse(…), NULL)) or by wrapping the call in TRY, which results in NULL if there was an error:
SELECT try(date_parse(s.pricing_date,'%m/%d/%Y %H:%i:%s')) AS dataconverted
FROM "mydatabase"."sales" s

IBM DB2 SQLException with "DB2 SQL Error: SQLCODE=-420, SQLSTATE=22018, SQLERRMC=DECFLOAT, DRIVER=3.66.46"

I am working on a Jasper report using iReport 5.6 and IBM DB2 as data source. I am passing a list of strings as a parameter to the report and that is where the problem rises. The query is below;
SELECT customers.mobile_number,
COALESCE(Count(DISTINCT transaction_entries.transaction_id), 0) AS
number_of_transactions,
COALESCE(Sum(Abs(transaction_entries.amount)) / 100, 0) AS
volume_of_transactions
FROM transaction_entries
JOIN customers
ON customers.id = transaction_entries.customer_id
WHERE transaction_entries.transaction_type = 'Seasonal'
AND transaction_entries.notification_text <> 'Notification'
AND customers.mobile_number IN ( $p ! {listOfMobileNumbers} )
GROUP BY customers.mobile_number
When I try to generate the report I get the error Caused by: com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-420, SQLSTATE=22018, SQLERRMC=DECFLOAT, DRIVER=3.66.46.
Any idea why ? and the possible solution ?
I would first verify that by commenting-out the last predicate of the WHERE clause avoids the error; i.e. redact the failing statement such that the IN predicate referencing the Jasper variable as input is no longer part of the query.
Then, determine what defines that variable replacement, from the output of the following query:
select '$p ! {listOfMobileNumbers}' from sysibm.sysdummy1
If the effect of the above query, used to reveal the data in that list, presents something like '1234,567,890', then I would suggest modifying the data that defines that list to reflect either of '1234','567','890' or 1234, 567, 890 instead.
FWiW: IMO the actual DDL [for column(s) or the TABLE] is much clearer to a reader than suggesting merely that:
The mobile_number field is returned from the database as a String and not a DECIMAL

Aggregate (sum,max,avg) function in Critera API JPA

In my criteria API query the following query where I query for three columns of my table works.
cq.multiselect(root.get("point").get("id"), root.get("player").get("userid"), root.get("amount"));
but when I want the sum of the column amount using the following query it gives a sql error. The query is
cq.multiselect(root.get("point").get("id"), root.get("player").get("userid"), cb.sum(root.get("amount")) );
The error that I am getting is.
{"id":"6","result":null,"error":"\r\nInternal Exception: com.sap.dbtech.jdbc.exceptions.jdbc40.SQLSyntaxErrorException: [-8017] (at 8): Column must be group column:ID\r\nError Code: -8017\r\n
Please help me with this, as I have been stuck on this for hours now. Thanks
The message is telling you that you need a group by clause in your query. Every column in the select clause (except the ones which are the result of an aggregate function) must be in the group by clause:
criteriaQuery.groupBy(root.get("point").get("id"),
root.get("player").get("userid"))

Nhibernate Expression.In limit

I am querying the Nhibernate criteria query with more then 2100 values for In clause.
I do something like Session.CreateCriteria(typeof()).Add(Expression.In("fieldName",arrayValue))
Where arrayValue contains more then 2100 values. I face error
Exception occurred:
UnknownError
NHibernate.ADOException: could not execute query ..then the query with more then 3000 values in array.
with some google help we found out that IN clause in Sql supports only till 2100 values.
Does anyone has faced similar issue earlier? We do not want to change the query as it is written in some generic way and not customized one.
This is a limitation of SQL Server. I wouldn't suggest doing this, but if you insist, you could work around it by creating a table-value sql function (see http://www.dzone.com/snippets/function-getting-comma) that splits up a string by commas (or whatever delimiter you want) and returns the values as a table, and then pass in all your ID's as (say) a comma separated list in 1 parameter and use a SQLCriterion in your criteria query.
eg:
criteria.Add(
new SQLCriterion("{alias}.ID IN (SELECT element FROM dbo.GetCSVValues(?))",
new[]{csvListOfIds},
new[]{NHibernateUtil.String}))
You could split the array into multiple batches, query multiple times, and then combine the result.