Does QlikView Accept all Sql syntax? - qlikview

I am good at SQL and know nothing about QlikView. Does QlikView uses exact SQL syntax? If I create SQL scripts, will that work in QlikView or I will need to change some syntax such as DateDiff function? I am in a dilemma whether to use QlikView or Report Builder. I know Report Builder will use SQL 100%.
Please help/guide.
Thanks.

Qlikview run SQL at it is.
Also there is some level of interaction between QV and SQL (if you want). For example having the following QV script:
set vDateFrom = 20140101;
set vDateTo = 20140201;
SQL
Select
*
From MyTable
Where
DateFrom >= $(vDateFrom)
and DateTo < $(vDateTo)
;
will result as following script being actually executed on the sql server:
Select
*
From MyTable
Where
DateFrom >= 20140101
and DateTo < 20140201

Related

MS Access Date() yields no results

I've searched but been unable to figure this out. I used to use MS Access many many years ago but have switched mostly to PHP and MySQL to do my work. But when I"m at work, I have to use those resources.
Trying to build a basic query from an ODBC connection to a SQL Server. One of the columns is a date field (SQL server field type: datetime).
When I build the query and enter Date() for my Where clause should be it yields no results.
SELECT dbo_Order.OrderStatusID,
dbo_Order.FillerOrderNumber,
dbo_Order.RelevantClinicalInfo,
dbo_Order.ReasonForStudy,
dbo_Order.ProcedureDescList,
dbo_Order.PlacerFld2 AS Modality,
dbo_Order.ScheduleDate,
dbo_Order.ExplorerStatus,
dbo_Order.SiteID
FROM dbo_Order
WHERE (
(
(dbo_Order.PlacerFld2) = "CRFL"
OR (dbo_Order.PlacerFld2) = "CT"
OR (dbo_Order.PlacerFld2) = "SAMR"
)
AND ((dbo_Order.ScheduleDate) = DATE ())
AND ((dbo_Order.ExplorerStatus) = "SCHEDULED")
AND ((dbo_Order.SiteID) = 1)
);
I've tried also doing something like Date: Format([ScheduleDate], "dd/mm/yyyy") but this also returns no results.
MS Access 2016
SQL Server 2008
If your ScheduleDate include any time values, Date() returns 1/1/2018 00:00 as a default so if your Scheduled date is 1/1/2018 04:34:00 it won't match.
Try using DateValue([ScheduleDate]) to return just the date
I would prefer:
dbo_Order.ScheduleDate >= Date() AND dbo_Order.ScheduleDate < Date() + 1
DateValue([ScheduleDate])has to be computed on every row and can't use an index (if any) what can affect query performance on huge data. See Access query won't work when dates have times In addition DateValue can't handle NULL values.

Access Runtime Linked Table Query Date Format

I have the following query executed on a Linked table in Access:
Select * From table WHERE DateField = #18-Dec-2016#
This date where clause is created with the following VBA code:
strWHERE = strWHERE & "DateField = #" & VBA.Format(txtDate, "dd-mmm-yyyy") & "#"
When using the full version of Access 2016 it it sent to SQL as:
Select * From table WHERE DateField = {d 18-Dec-2016}
This works! However, when using the Access 2016 runtime, it is sent to SQL as:
Select * From table WHERE DateField = {ts 18-Dec-2016}
and it fails.
I am using SQL Server Profiler to find the exact SQL being sent.
Any ideas?
EDITS:
Tried changing format to yyyy-mm-dd
Tried added "00:00:00" to the VBA code building the where clause, and this does not change what I see sent to SQL through the profiler.
SOLVED:
For some reason, the behaviour of linked table queries is different between the full version of Access and the 2016 Runtime.
In the Runtime version, the data type of the field in the linked table is used to format the query. So because the DateField was DateTime, it passed the where clause as ts. BY creating a view and formatting the date as just a date, this was solved.

Why doesn't CAST( AS ) sometimes work on BigQuery?

I tried two queries:
SELECT CASE WHEN CAST(CURRENT_TIMESTAMP() AS DATE) = CURRENT_DATE() THEN 1 ELSE 0 END;
and
SELECT CASE WHEN DATE(CURRENT_TIMESTAMP()) = CURRENT_DATE() THEN 1 ELSE 0 END;
The first query fails in Legacy SQL but not in Standard SQL, while the second query works. (Standard SQL is currently not covered by SLA.)
There are two problems with first query in Legacy SQL:
CAST(... AS DATE) in Legacy SQL only works on strings, while CURRENT_TIMESTAMP returns TIMESTAMP type
CURRENT_DATE in Legacy SQL is misleadingly returns STRING, not DATE :(
Both of these problems are indeed fixed with Standard SQL
Legacy SQL has limited support for DATE. For more information, see Civil time in legacy SQL
So, if you need to be in Legacy SQL - you should use second query in your case with DATE() function

query to_date issue

Below query is giving me two different result for two different oracle database. ( database version I am not aware of )
I want to ask like TO_DATE function varies from database version ?
select * from ACC WHERE CHANGE = TO_DATE('01/02/2015','MM/DD/YY');
Note that I am facing issue in only = but < and > working fine.
In 1 db : this query is giving 1 record
In 2 db : this query is giving 0 record.
In DB : CHANGE value is 02-JAN-14
As far as I know, to_date() hasn't changed. More likely is that you have a time component on your column change, which prevents = from working. Try this:
select *
from ACC
where trunc(CHANGE) = TO_DATE('01/02/2015','MM/DD/YY');
Or, how I would prefer to write this:
where change >= DATE '2015-01-02' and
change < (DATE '2015-01-02') + 1
Using the date keyword, you can use ISO standard formats. This version also allows the use of indexes on the change column.
if they are on the same server is strange. If you are on two different servers verify that the date format of the server is the same.
You can see it in the settings under NLS

Cannot find a common SQL that will work both for H2 and Postgres

In my project, I am using Postgres database, but sometimes, for development, I am using H2.
I am trying to define an sql script which will update a timestamp column as described below, but I could not find a single format that can be applied both to Postgres and a to H2.
Basically, the sql is trying to set the timestamp to be NOW + 1 week.
Here is the sql that works for Postgres:
update mytable set mytime = CURRENT_TIMESTAMP + INTERVAL '7 days';
Here is the sql that works for H2:
update mytable set mytime = CURRENT_TIMESTAMP + 7;
Can someone suggest an single sql that can do the same for both databases?
According to my test, this works for both H2 and PostgreSQL:
update mytable set mytime =
cast(cast(current_timestamp as date) + 7 as timestamp) +
cast(current_timestamp as time);
It is a bit strange I agree, but it is the only way I found with current versions of H2 and PostgreSQL.
We ran into a similar issue where we use PostgreSQL for our app, but our unit tests use H2. We ended up just moving the date arithmetic into the application code. So, using the example above, the sql was change to be
update mytable set mytime = ?;
And then in the application code (using Java) we figured out the time:
Instant future1Week = Instant.now().plus(1, ChronoUnit.WEEKS);
And bound that value in the PreparedStatement.