Access SQL for sorting by date with TempVars - sql

im trying to make a query from the use of TempVars
im Using SQL to run the query but every time i try, it return Invalid date value
this is the line that will not work
this returns error
WHERE ((([Table].[Issue Date])>=#[TempVars]![tmpDateFrom]# And ([Table].[Issue Date])>=#[TempVars]![tmpDateTo]#));
this returns fine
WHERE ((([Table].[Issue Date])>=#10/12/12# And ([Table].[Issue Date])>=#11/12/12#));
I have checked the TempVars [tmpDateFrom] and [tmpDateTo] and they out put the date value i need.
Please help

Thank you all or the help.
due to the requirement of the database #Nicarus had the right answer this is the solution for those still wondering.
WHERE ((([Table].[Issue Date])>=[TempVars]![tmpDateFrom] And ([Table].[Issue Date])>=[TempVars]![tmpDateTo]));

Related

Convert Integer to Date in Snowflake using Error Handling

I have a requirement where integer value should be converted to date type in Snowflake.Initially I used following query to get the desired result:
SELECT TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
2019-07-09
Now when I used same query for the input - "20200034", I am getting following error:
select TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
Can't parse '20200034' as date with format 'YYYYMMDD'
"20200034" is actually coming from one of the columns in snowflake table. To resolve this issue I tried using "TRY_TO_DATE" function, but output of "TRY_TO_DATE" function is giving incorrect result. Please find details below:
select TRY_TO_DATE(TO_varchar(19000000+1200034))
1970-08-22
As per Snowflake documentation, error handling function does not support optional format argument supported by TO_DATE , DATE.
https://docs.snowflake.com/en/sql-reference/functions/try_to_date.html
You can set the DATE_INPUT_FORMAT for the session before calling the TRY_TO_DATE function.
I suggest you contact Snowflake support and ask them to enable try_to_date with format string - it's available but needs to be enabled manually.
However you have to be aware that TRY_TO_DATE on '20200034' will be resolved to NULL.

how to add days in orient db

How do we add days to dates in Orient db?
select sysdate()+1 from safetyplan;
It is giving same output as sysdate().
1 is not getting added. Can you help me, please?
According to Orientdb doc 2.2:
sysdate() returns the current date time. If executed with no parameters, it
returns a Date object, otherwise a string with the requested
format/timezone.
So one possible way is to convert date object to long using .asLong() method of date object.Then do the necessary addition.Convert it back to date using .asDate() method.
Example:To get a day added to current day use:
select sum(sysdate().asLong(),86400000).asDate() from safetyplan;
Note:we are adding in milliseconds and 1 day=1000*60*60*24 milliseconds
NB:Thought that this answers may help someone and sorry for answering my own question.

Compare dates using Dateserial in Access 2007 SQL

I have the following SQL
SELECT P1.Column1, P1.NextApprovalDate
FROM Procedures P1
WHERE DATESERIAL(YEAR(P1.NextApprovalDate), MONTH(P1.NextApprovalDate), 1 )
= DATESERIAL(YEAR(Date()), MONTH(DATE()) + 1, 1);
I get an error which is "Data type mismatch in criteria expression". I tried using the CDate and the Format functions in conjunction as well but continue to get the same error. The SQL runs fine when I am selecting the criteria there. How should the criteria be formatted?
Ok. I got this to work but it is kind of weird the way Access wanted it. The = sign never worked for the comparison. Why I don't know. The BETWEEN worked. If someone could find a way to make the '=' work, do let me know. Thanks to #Hansup for pointing me in the right direction.
SELECT P2.Column1, P2.NextApprovalDate
FROM (SELECT Procedures.Column1, Procedures.NextApprovalDate FROM
Procedures WHERE Procedures.NextApprovalDate IS NOT NULL) AS P2
WHERE DATESERIAL(YEAR(P2.NextApprovalDate),MONTH(P2.NextApprovalDate),1)
Between DATESERIAL(YEAR(Date()),MONTH(Date())+1,1) And
DATESERIAL(YEAR(Date()),MONTH(Date())+1,1);

In statement with parameters in Crystal Report Command object

I am trying to modify the code of an exsisting SQL report. This report uses a command object. Currently the SQl codes says the following:
WHERE **dept.definition_id ={?Measure}**
AND (({?Period Interval}=2
AND dept_qd_later.sum_facts_id IS NULL
AND dept_qd.DENOMINATOR_QUARTER IS NOT NULL)
OR ({?Period Interval}=3
AND dept_md_later.sum_facts_id IS NULL
AND dept_md.DENOMINATOR_MONTH IS NOT NULL))
LAST
I would like to modify the "Measure Parameter" to accept multiple values. I have updated the command parameter box to accept multiple values. I have tried to modify the SQL to the below in statement:
WHERE **dept.definition_id in({?Measure})**
AND (({?Period Interval}=2
AND dept_qd_later.sum_facts_id IS NULL
AND dept_qd.DENOMINATOR_QUARTER IS NOT NULL)
OR ({?Period Interval}=3
AND dept_md_later.sum_facts_id IS NULL
AND dept_md.DENOMINATOR_MONTH IS NOT NULL)))
LAST
However, when I try to insert multiple measure IDs, the report does not run. Can someone help me figure out what I am doing wrong? I am a Crystal novice so please respond in plain language. Thanks!
I think David is right. I tried something similar with a command object and it works when entering a comma separated list into the parameter prompt. Which means that you don't need to set the "allow multiple values" option on the parameter.
If the field were a string, you would have to enter the values with quotes as if they were part of the SQL statement.

Adding an error message to return. SQL Server

Well, I'm trying to construct some error reporting.
Current snippet of code, which will put into a stored procedure after I get this code correct...
begin
select *
from dbo.DIM_S17_Detail
Where ((LEN(New_Acc_Flag) >1 or ISNUMERIC (Substring(New_Acc_flag, 1, 1)) = 1))
end
So, the defined datatype is either a Y/N - Alphanumeric, so it picks out ISNUMERIC as 1, so it will bring up the selected records which ARE numeric - so these records are incorrect...
I hope you still follow...
So, if a 'New_Acc_Flag' is TRUE, it will bring up those record(s) and should return a message something like "Y/N not selected" or "Y/N Value only".
Thanks again.
Please bear in mind I'm a noobie to SQL.
If I understand what you want correctly you can use THROW or RAISERROR