sql remove date and time stamp from string - sql

Do any of you awesome DBA fellows know how to remove both the Date and Time stamp from an SQL string?
For example, I have a string that has this:
"2014-04-17 15:38:53.2389 Unexpected Failure System.ServiceModel.FaultException: Unexpected Failure"
I want to remove the "2014-04-17 15:38:53.2389" and just be left with this:
"Unexpected Failure System.ServiceModel.FaultException: Unexpected Failure"
I can get it to work using SUBSTRING
SUBSTRING(CAST([stacktrace] AS NVARCHAR(500)),25 ,LEN(CAST([stacktrace] AS NVARCHAR(500)))) as stackTrace
But this isn't very elegant and could cause problems for string that don't have dates at the start.
I can find ways to remove the TimeStamp or to remove the Date, but I can't find a way to remove both.
Any help would be much appreciated.
Thanks

I don't know the exact code, but: It should be possible to filter the string according to the first alphabetic letter in the string.

at least provide a generic format of your error like you are going to get date and timestamp or just time stamp or some text your error always start with

You can use as following:
check if it is date at start and design the substring accordingly under if-else
select isdate(convert(varchar(10),'2014-04-17 15:38:53.100',111))
possibly you can use as
if (select isdate(convert(varchar(10),<use substring to get first 25 values>,111)))=1
then <design substring to remove and use data>
else
<use as-is>

Related

Convert date in snowflake to YYYYMM

Snowflake documentation says to use TO_DATE('2022-01-01', 'YYYYMM'), however, when running that I receive the error message:
"Error: too many arguments for function [TO_DATE("policy_effective_date", 'YYYYMM')] expected 1, got 2"
Any help is appreciated.
I was expecting to see 2022-01-01 turn into 202201. Even if I need to bring in DD that's fine too, I can just capture the LEFT 6 digits, but regardless the system is saying it's too many arguments.
TO_DATE() function accepts string/varchar format date and converts to Date Data type. For that we need to pass existing String date type format to parse. To Convert to the required format we need to use to_varchar as given in the documentation. https://docs.snowflake.com/en/sql-reference/functions-conversion.html

How do I get the right date format after using get text on the folder date?

I have tried everything that I can think of to get the right date format. Can anybody help with this RPA-problem in UiPath. I have used the 'get text' activity to get the folder date and after that tried to use the
Datetime.ParseExact(Str variable,"dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).
It gives me the error:
Assign: String was not recognized as a valid DateTime.
Your help is much appreciated.
edit: I have now sought help from a friend who figured it out. The error was in the string, which could not be seen, because there was an invisible character in the string that I extracted through 'get text' activity. The solution is in 2 steps:
assign another variable to the exact same date and use an if statement to find out if these two strings are equal and you will find out that they are not.
Now use a regex to capture only digits and slash/hyphen which will get rid of the invisible character.
Try to use "dd_MM_yyyy" instead of "dd/MM/yyyy".
The reason is because UiPath/VB.Net has a habit of using US date formatting even though you're using Culture Info...It's a real pain
Try this:
pDateString = "21/02/2020"
Assign a Date type variable = Date.ParseExact(pDateString,"dd/MM/yyyy",nothing)
Here we're telling the parser to use English format date...The Date type returned will be in US format but you can simply convert back to uk IF needed by using something like:
pDateString("dd/MM/yyyy")

Firebird ISC 335544334 - Conversion error from string "2002-07-07 22:00:00.000"

I am currently working on a project which allows you to import data from an Excel file. I use the Programm RazorSQL. But every time I start the import, the
ISC error code 335544334 occures ->
An error occurred: java.sql.SQLException: conversion error from
string "2002-07-07 22:00:00.000" [SQLState:22018, ISC error
code:335544334]
Does Firebird use some special Date formats? I really need an answer, it's very important. This problem keeps me waiting to continue with my work...
The error message indicates that Firebird tried to convert the string value 2002-07-07 22:00:00.000 to a datatype other than CHAR/VARCHAR and did not succeed because the string value is invalid for the target datatype. The format as shown will correctly convert to a TIMESTAMP, which means that you are assigning this either to the wrong column, or the column has the wrong type. For example, a DATE has no time component in dialect 3, so converting a string with a time component will fail with this error, as will converting to a numerical column (INTEGER, BIGINT, etc).
Without more information about the columns involved and the exact method of import, it is not possible to provide a more specific answer.

vb.net datetime.parseExact error message saying invalid format

Hi am trying to use the datetime.parse exact object in vb.net, but I keep getting an error saying invalid format. Here is my statement, could anyone tell me what I am doing wrong??
Dim TimeStart As Date
TimeStart = DateTime.ParseExact("2013.07.15-07:10:02", "yyyy.MM.dd-HH:MM:SS", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
The error is because the seconds must be lower case. Also, you're asking for the month twice. I suspect this is the format string you need:
yyyy.MM.dd-HH:mm:ss
Just as an informational bit, the upper case 'H' means it's looking for 24-hour time, instead of 12-hour time. Lower-case 'h' would mean 12-hour time. Here is the reference for custom datetime format string rules:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Reporting Services - handling an empty date?

Hey, I have a report parameter which looks like this: 01.01.2009 00:00:00
Its a date (as string), as you might have guessed :). The problem is, this param can be an empty string as well. So I tried those expressions:
=IIf(IsDate(Parameters!DateTo.Value), CDate(Parameters!DateTo.Value), "")
=IIf(Len(Parameters!DateTo.Value) > 0, CDate(Parameters!DateTo.Value), "")
Both dont work and the value for the textfield where I print the expressions result is always #Error. As soon as I remove the CDate stuff, it works, but I have to use it. IS there another way to achieve that? What I want is to display nothing if its not a date or the date (format dd.mm.yyyy) if its a date.
Ideas?
Thanks :)
All arguments to the IIf are evaluated, which results in your error, since the CDate will fail for an empty string.
You can get around this by just writting a function along these lines, using a standard if statement:
Function FormatDate(ByVal s As String) As String
If (s <> "") Then
Return CDate(s).ToString()
Else
Return ""
End If
End Function
Then call it with: =Code.FormatDate(Parameters!DateTo.Value)
First, fix your database to properly store dates rather than doing these workarounds. You probably have bad data in there as well (Feb 30 2010 for example or my favorite, ASAP). Truly there is no excuse for not fixing this at the database level where it needs to be fixed except if this is vendor provided software that you can't change (I would yell at them though, well notify them really, and ask them to fix their data model or go to a new product designed by someone who knows what they are doing. A vendor who can't use dates properly is likely to have software that is very poor all around).
In the query that you use to select the infomation, have you considered just converting all non-dates to null?