Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
Well, I have a problem with sending data. There are three stations, all of which work on-site on an ongoing basis. I checked the system settings and settings and one of the stations was updated to the 21H2 version (I set everything up as it is at the station where it works). Unfortunately, this option did not help. I also turned off the error on the server by setting it on the station.
I'm adding an error dump
I think SQL Server assumes another format than the one you
intended and another value causes the error.
Use CONVERT(smalldatetime, YourColumn, 101) to force format mm/dd/yyyy, or
use CONVERT(smalldatetime, YourColumn, 103) to force dd/mm/yyyy.
To prevent this in the future:
Always store dates as a datetime or smalldatetime column.
When you have to convert character data to datetime, always use one of
the unambiguous formats:
For date only: yyyymmdd
For date plus time: yyyy-mm-ddThh:mm:ss.mmm (where the optional .mmm
part denotes the milliseconds)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I am trying to create a localized report from an MSSQL Database which contains information about transactions with a BUSINESSTRANSACTIONDATE which is a Timestamp.
This Timestamp is stored in UTC, however the Machine is running on Europe/Berlin Timezone, this is also shown in the REPORT_TIME_ZONE parameter of JasperReports.
The data should be filtered by parameters (Start and Enddate). I am currently not sure what the proper way is to solve this. Currently the data seems to be outputted as is, but apparently Jasper is already figuring out the correct timezone.
A transaction which happened Feb 15, 2023, 1:04:48 AM according to the Application is displayed as 15-Feb.-2023 00:04 +0100. So that seems to be right(?).
So what would be the best approach to:
Format the Dates correctly in the local (Europe/Berlin) Timezone
Make it possible to put in the Start- and Enddate and use it as a parameter in the SQL Query. Start and Enddate could be UTC or better(?) the Local timezone.
Since I am planning to use JasperReports from a Java application it might make sense to pass the Start and Enddate as UTC, but for local development it might cause confusion while designing the report.
I am thinking of taking the REPORT_TIME_ZONE Parameter and putting it as a parameter in the SQL queries, however this resulted in strange error messages.
I guess I can format the Date with an expression in JasperReports to the correct Local date representation, but I am not sure if I should do that or do the conversion in the SQL query.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am working on a table that will display employees' Shift Start and End times. Also, it will have the employees' Punch In and Punch Out times.
Is there a way to remove the nanoseconds and change the 24-hour Time format to AM/PM? I'm using Microsoft SQL Server Management Studio 18.
Yes, you can format your datetime column using the format function:
SELECT FORMAT(ShiftStartDate, 'yyyy-MM-dd hh:mm:ss tt')
FROM yourtable
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Trying to select data only between a range.
select ITM_NBR,
TOT_IVO_ITM_QTY,
Count(*)
FROM dataset
WHERE
bus_dt BETWEEN '2-14-2020' AND '2-15-2021'
Failed conversion to numeric value. Tried without single ticks and it returned zero rows which makes me believe that the column is stored as a VARCHAR. Tried Casting the bus_dt column into a date format.
CAST(bus_dt AS DATE FORMAT 'mm/dd/yyyy') BETWEEN 2/14/2020 AND 2/15/2021
Again failed conversion.
I feel as if I’ve tried every combination and can’t get anything to work of casting and putting the date values in yyyy-mm-dd, mm/dd/yyyy, etc. formats.
And also when I HELP VIEW to see the column type I get “?”.
Kind of at a loss right now.
After I thought I tried everything I figured it out....
I was not formatting my date literals correctly .... faceplam
DATE'yyyy-mm-dd'....
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a lot of issues using the datediff function in SQL Server.
I have two tables that I want to join based on the time gap between observations; the tables contain arrival times of shipments as follows yyyy-mm-dd hh:mm:ss.
I found a different question of which the answer will (hopefully) help me with the join bit. The code provided by said example states the following, and this is where the struggles begin.
Abs(DateDiff("d", pi.Product_Interest_Date, l.Lead_Date)) AS Date_Gap
Source: Join two tables on the same date or closest date (before or after)
However, I need to find the date gap between values based on the full date, so from year to seconds. Am I correct in understanding that the datediff function only accepts one level (i.e. only day or minute), or am I doing something wrong?
If the former is the case, is there an easy way to do what I want to do?
First, the syntax in SQL Server for days is:
abs(DateDiff(day, pi.Product_Interest_Date, l.Lead_Date)) AS Date_Gap
The syntax that you are using is MS Access syntax.
SQL Server does not have an interval type. You can get the difference in seconds and then convert to another unit. For instance, decimal days is:
abs(DateDiff(day, pi.Product_Interest_Date, l.Lead_Date)) / (24.0 * 60 * 60) AS Date_Gap
You don't provide sample data and desired results that describes the exact results you want, but this should put you on the right track. If this doesn't fully answer your question, then you should ask a new question with sample data, desired results, and a clear explanation of the logic.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to complete cards numbers in sql. I have the prefix =11111 and the number of the card which is variable, therefore it could be '25' or '2130' but at the end I must have 14 numbers. So I need to fill spaces with zeros.
I've read about 'LPAD' but I don't understand very well this method.
You could use lpad, but if you're starting with a number you could use a 9-digit format model instead, and concatenate that onto your prefix:
select '11111' || to_char(25, 'FM000000000') from dual;
11111000000025
The FM format modifier stops Oracle adding a space for a potential +/- sign indicator.
SQL Fiddle demo
Use the ZEROFILL attribute.
But your database should only be responsible for saving data and not changing it before saving.
The best way would be to send the zerofilled data to the database server.