![]() It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position. The STUFF function inserts a string into another string. This approach will work if your string is always the same length and format, and it works from the end of the string to the start to produce a value in this format: YYYYMMDD HH:MM:SSįor this, you don't need to separate the date portion in anyway, as SQL Server will be able to understand it as it's formatted. Nevertheless, your method will prove handy should I need to convert a stupiddate created by a moron to a DATE column. but this is better done on the client (if at all). When you have a valid date as a string literal, you can use: SELECT CONVERT (CHAR (10), CONVERT (datetime, '20120101'), 120). This allows me to join it to a fact table which has a DateKey column with that format. Now you don't have to worry about the formatting - you can always format as YYYYMMDD or YYYY-MM-DD on the client, or using CONVERT in SQL. I just need to create a column with the YYYYMMDD format. In SQL Server, you can use CONVERT or TRYCONVERT function with an appropriate datetime style. The date format was fine, it is just a date column no string attached. SELECT CONVERT(DATETIME, AS FormattedDate In Oracle, TODATE function converts a string value to DATE data type value using the specified format. ![]() ![]() You can use the STUFF() method to insert characters into your string to format it in to a value SQL Server will be able to understand: DECLARE NVARCHAR(20) = '20120225143620' ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |