I am trying to create a report that has three optional parameters using a command in Crystal Reports 2008. The only one I can't get to work is the date parameter (seems Oracle does not treat dates the same as SQL Server).
I want the user to be able to pick and choose which parameter they would like to use; one, two, or all three. It works beautifully when I run it in TOAD and hard code the dates, but it will not run in Crystal reports using the syntax to create the parameters.
I have done this a thousand times in a SQL server environment but can't get it to work in Oracle.
The field is type is DATE in the Oracle table.
Here is the syntax from my Report command for the 3 parameters:
AND ( ( CLIL. ITEM_TAG IN ('{?tag}') OR CLS.DESCRIPTION IN( '{?desc}')
OR trunc (CLIL.ISSUE_DATE) BETWEEN to_date ('{?StartDate}', 'mm/dd/yyyy') and to_date ('{?EndDate}', 'mm/dd/yyyy' )))
Crystal reports doesn't accept the Oracle syntax.. you need to use the functions provided by the CR to do manuplations of dates... and then use that in CR.
Create a Start Date and End Date as date parameters in CR and then use those.
(CLIL.ISSUE_DATE) >= {?StartDate} and (CLIL.ISSUE_DATE) < {?EndDate}
Here start date and end date are Date datatype parameters.
if (CLIL.ISSUE_DATE) is a datetime parameter then use the function Cdate provided by the crystal.
Related
Actually I was trying to get all columns within a date range in Oracle db and I am successful in doing so in SQL Developer but when I execute the same code in SQL command line interface I get an error
ORA-01843 : not a valid month
I know its an error which comes in to_date format but it gets executed in SQL developer as exactly I expected but not in SQL command line. Why does this happen??
select to_date('01/04/2020') from dual;
Even this command is not working.
I had tried all format methods for the to_date method conversion and I checked nls_date_format which shows 'DD-MM-RR'
I'd suggest you to always provide appropriate format mask. Don't rely on Oracle implicitly converting & guessing what you wanted to do.
String that looks like '01/04/20' could be anything, depending on format you used (dd/mm/yy, yy/dd/mm, mm/yy/dd ... all of that is valid, but only one is correct).
SQL> alter session set nls_Date_format = 'dd-mm-rr';
Session altered.
SQL> select to_date('01/04/2020', 'dd/mm/yyyy') result from dual;
RESULT
------------------------------
01-04-20
SQL>
I'm fairly new to U-SQL so this may be a simple question.
I have a field, [utc_timestamp], in an ADL table with a unix time stamp in the form "1497178877" which measures the number of seconds from 1970-01-01.
Is there any easy way to convert this time stamp in U-SQL to both a date in the form of "2017-06-11" and a date time object?
My initial attempt didn't seem to work quite right.
#table =
SELECT * FROM
( VALUES
(1497178877)
) AS T(seconds);
DECLARE #dateStart = new DateTime(1970, 01, 01);
#result =
SELECT #dateStart.AddSeconds(seconds).ToString("yyyy-MM-dd") AS newDateString,
#dateStart.AddSeconds(seconds) AS newDate
FROM #table;
OUTPUT #result
TO "/Temp/Dates/Example1.txt"
USING Outputters.Tsv();
U-SQL is using C# for the expression language, so you can use C#/.NET to do it.
Here is a link answering how to do it in C#: How can I convert a Unix timestamp to DateTime and vice versa?
Since we are currently on .NET Runtime 4.5.2, you will not be able to use the 4.6 built-in method (we plan to upgrade to a newer version of the runtime, but I do not have an ETA yet).
If you want to avoid writing the transformation inline as a C# expression you can either deploy it via VS's code behind, with a U-SQL Func variable or create and register an assembly containing the UDF.
I am using sqlite for local database in mobile and in my database. i want to know that
How to get current date format in SQLITE? I want to get date in the next format: MM/dd/yyyy
To get the current date you can use:
SELECT date('now');
Note: This is NOT a server date, it's the same time you get if you query the date and time directly from your application because SQLITE runs in-process.
It's mostly useful for putting a current time into a table or for some simple calculations if your language's date processing is very poor.
To do the calculations see the SQLITE Documentation
See the docs for formatting too for example:
SELECT strftime('%Y-%m-%d %H:%M:%S', datetime('now'))
According to the SQLite documentation as of this writing (3/30/2020), in the section titled "The DEFAULT clause", it is recommended that a constant value be used instead of a sub-query.
In my experimentation, I also ran into issues with the SQLite CREATE TABLE statement that was generated during model creation by EF Core 3.0 when using SELECT datetime('now'). The SQLite data provider complained of a syntax error when using a SELECT statement within the CREATE table statement. As such, I would recommend using the CURRENT_TIMESTAMP keyword.
for your concrete case, this is what you need:
strftime('%m/%d/%Y',date('now'))
I have a stored procedure written in Oracle. I'm using a where condition in which i'm comparing two dates. I have a strange problem where the procedure works from oracle perfectly and when run from asp.net it just returns 0. Please look below for the procedure
PROCEDURE SAMPLEPROC
(
P_DATE IN VARCHAR2,
P_COUNT OUT NUMBER
)
AS
BEGIN
SELECT count(*) INTO P_COUNT from dual where
to_date(sysdate,'dd-mm-yyyy')=to_date(P_DATE,'dd-mm-yyyy');
END;
Now, when i run the above code with below input.
INPUT : 11-02-2014
OUTPUT FROM ORACLE : COUNT=1
OUTPUT FROM ASP.NET : COUNT=0
Then, After wasting long time, My friend just changed the format of the date to dd-mm-rrrr as shown below
SELECT count(*) INTO P_COUNT from dual where
to_date(sysdate,'dd-mm-rrrr')=to_date(P_DATE,'dd-mm-rrrr')
After making the changes when we run with the same Input as above
INPUT : 11-02-2014
OUTPUT FROM ORACLE : COUNT=1
OUTPUT FROM ASP.NET : COUNT=1
Why is it like this? Why is it behaving in this way when run from ASP.NET
Please someone give me a explanation for this?
Added: From ASP.NET my date will be always coming as 11-02-2014 ie DD-MM-YYYY format and its not a Date datatype. Its just a string. The same procedure works perfectly when running from ORACLE and when sent data from Asp.net it gives me 0. I debugged it I saw that the data coming from asp.net is perfectly the same which I pass from oracle when testing.
So, I just need an explanation why it could be like this when YYYY was replaced with RRRR
when,
SELECT TO_DATE(SYSDATE,'DD-MM-YYYY') FROM DUAL;
AND
SELECT TO_DATE(SYSDATE,'DD-MM-RRRR') FROM DUAL;
returns the same data '11-02-2014'
SELECT count(*) INTO P_COUNT from dual where
trunc( sysdate) =to_date(P_DATE,'dd-mm-yyyy')
It has to be like this.
sysdate already returns a date.
I believe ur nls_date_format is different in your sqlplus and asp connection.
So, to_date(sydate) is attempt to work on some string.. which I guess is mm-dd-yyyy or dd-mm-rr(most probably) and so there could be mismatch.
SELECT value
FROM nls_session_parameters
WHERE parameter = 'NLS_DATE_FORMAT'
please run the above query in both places to catch the mismatch!
I have the following piece of inline SQL that I run from a C# windows service:
UPDATE table_name SET
status_cd = '2',
sdate = CAST('03/28/2011 18:03:40' AS DATETIME),
bat_id = '33acff9b-e2b4-410e-baaf-417656e3c255',
cnt = 1,
attempt_date = CAST('03/28/2011 18:03:40' AS DATETIME)
WHERE id = '1855'
When I run this against a SQL Server database from within the application, I get the following error:
System.Data.SqlClient.SqlException: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
But if I take the piece of SQL and run it from SQL Management Studio, it will run without issue.
Any ideas what may be causing this issue?
Ambiguous date formats are interpreted according to the language of the login. This works
set dateformat mdy
select CAST('03/28/2011 18:03:40' AS DATETIME)
This doesn't
set dateformat dmy
select CAST('03/28/2011 18:03:40' AS DATETIME)
If you use parameterised queries with the correct datatype you avoid these issues. You can also use the unambiguous "unseparated" format yyyyMMdd hh:mm:ss
But if i take the piece of sql and run it from sql management studio, it will run without issue.
If you are at liberty to, change the service account to your own login, which would inherit your language/regional perferences.
The real crux of the issue is:
I use the following to convert -> date.Value.ToString("MM/dd/yyyy HH:mm:ss")
Please start using parameterized queries so that you won't encounter these issues in the future. It is also more robust, predictable and best practice.
I think the best way to work with dates between C# and SQL is, of course, use parametrized queries, and always work with DateTime objects on C# and the ToString() formating options it provides.
You better execute set datetime <format> (here you have the set dateformat explanation on MSDN) before working with dates on SQL Server so you don't get in trouble, like for example set datetime ymd. You only need to do it once per connection because it mantains the format while open, so a good practice would be to do it just after openning the connection to the database.
Then, you can always work with 'yyyy-MM-dd HH:mm:ss:ffff' formats.
To pass the DateTime object to your parametrized query you can use DateTime.ToString('yyyy-MM-dd HH:mm:ss:ffff').
For parsing weird formatted dates on C# you can use DateTime.ParseExact() method, where you have the option to specify exactly what the input format is: DateTime.ParseExact(<some date string>, 'dd/MM-yyyy',CultureInfo.InvariantCulture). Here you have the DateTime.ParseExact() explanation on MSDN)
It's a date format issue. In Ireland the standard date format for the 28th of March would be "28-03-2011", whereas "03/28/2011" is the standard for the USA (among many others).
I know that this solution is a little different from the OP's case, but as you may have been redirected here from searching on google the title of this question, as I did, maybe you're facing the same problem I had.
Sometimes you get this error because your date time is not valid, i.e. your date (in string format) points to a day which exceeds the number of days of that month!
e.g.: CONVERT(Datetime, '2015-06-31') caused me this error, while I was converting a statement from MySql (which didn't argue! and makes the error really harder to catch) to SQL Server.
You could use next function to initialize your DateTime variable:
DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )
JAVA8: Use LocalDateTime.now().toString()
i faced this issue where i was using SQL it is different from MYSQL
the solution was puting in this format:
=date('m-d-y h:m:s');
rather than
=date('y-m-d h:m:s');