Questions tagged [sql-convert]

SQL `CONVERT()` is a general function that converts an expression of one data type to another.

SQL CONVERT() is a general function that converts an expression of one data type to another.

Note that this is a non-standard function. The ANSI/ISO SQL standard has the CAST() function.

Reference

104 questions
0
votes
2 answers

How to write out/convert YYYY-MM-DD to "Month, DD, YYYY" in SQL

I'm trying to convert some dates I have that written as 2004-01-05 into January 1, 2004. I can't use DATEFORMAT() because it's not a supported built in function in my database. I'm using the up-to-date version of Azure for my database. If I try to…
0
votes
0 answers

'convert' statement of sql in pyspark or spark...?

Ok, so I'm trying to "translate" some stuff into pyspark. The statement that I have is the following: CONVERT(VARCHAR(6), DATEADD(MONTH, -1, DATEADD(MONTH, -1, GETDATE())),112) AS CURRENT_DATE I've been searching and reading the documentation, but…
0
votes
1 answer

Creating a Date Field from a big string Field

Good Morning, I have a Table and the field(type:string) "properties_content" is always filled as the following pattern: "Month DD, YYYY"/"Month D, YYYY" + "a Written Review" Like: May 18, 2023 Loved the message January 1, 2022 Nice one February 13,…
marceloasr
  • 343
  • 1
  • 3
  • 11
0
votes
1 answer

Find min date from a column which has values DD-MMM-YY format stored as string

One of the column(file_date) in a table is of type string and has values of dates in DD-MMM-YY format. How do I find min(date) from the column. I wrote simple query Select min(file_date) from tablename It gives output as: 01-Dec-22 But there are…
Xenon
  • 11
  • 2
0
votes
0 answers

Exponential conversion to number is wrong in SQL Server

I am inserting some data from python to sql server. In the dataframe, the data looks ok. However after inserting into sql table, the number converts to some exponential expression. I tried to convert it into a number but the output is not correct.…
Sriram
  • 433
  • 4
  • 20
0
votes
0 answers

Select part of the byte array as text

I have MS-Sql table with column named "data", it is varbinary(1000) Binary array saved there always contains string starting at byte 16 (30 next byte). Is is possible to select (cast) only this string? Something like: SELECT CAST(data as varchar)…
Viliam
  • 636
  • 9
  • 17
0
votes
3 answers

SQL - Insert Into - Convert Datatype

my table consists of the following fields: IDTemp int NO NULL Nr_ nvarchar(50) NULL Description nvarchar(50) NULL [Description 2] nvarchar(50) NULL Price money NULL Now I want to insert some values into that table from another database,…
qawas
  • 3
  • 3
0
votes
0 answers

Select query unable to retrieve result

I have a query which on executing, gives the below error. Conversion failed when converting date and/or time from character string. The Query is SELECT EMPLOYEE_NUMBER FROM PER_PERSON WHERE IS_ACTIVE = 'Y' AND '31-01-2022 00:00:00' BETWEEN…
ispostback
  • 330
  • 2
  • 7
  • 23
0
votes
2 answers

How do I update a varchar column that has a number by adding another number?

I have a column that is varchar(80) and is storing dollar amounts (no $ sign). I would like to update the value by adding another amount, e.g. the existing amount is 96.73 and I want to add 1.00 to make 97.73. I have tried cast and convert without…
mirons
  • 1
  • 1
0
votes
1 answer

Problem with finding datetime entries which are related to today in a SQL Server table

I have a table with a varchar column with different values in it. Some of the values in this column are in fact datetime stamp but written in varchar data type. I wish to find entries which contain datetime AND are related to today. So, my table is…
Iraj
  • 319
  • 3
  • 17
0
votes
1 answer

Sort by year as nvarchar and then numerically

I have an nvarchar column that in essence stores the following data: 20-198 99-135 19-135 20-197 20-195 99-435 The first two numbers represent the year created and the last numbers represent the id of the unit made that year. Whenever I sort I get…
0
votes
1 answer

XML input string got cut off when using convert() in sql

I am trying to update an item in the table with following code: UPDATE My_Table SET My_Xml = CONVERT(XML, 'MY_SUPER_LONG_XML_STRING') WHERE id = '001'; The XML string I have is around 100 lines long. I understand that this way CONVERT()…
cxc
  • 201
  • 2
  • 10
0
votes
2 answers

Select a date in a string and convert it to datetime

I have a string like: 'SPY US 03/20/20 P45' I want to select just the date from the string. My current query is: Select Ticker, SUBSTRING(Ticker, PATINDEX('%[0-9][0-9]/[0-9][0-9]/[0-9][0-9]%',o.Ticker),8) AS 'myDate' FROM TABLE This returns: 'SPY…
0
votes
1 answer

Read datetime value from CSV file into teradate

I fairly new to teradata. I'm trying to read a csv file which has create_date column as datetime, trying to import the file into teradata temp table but unable to succeed. Please help me to resolve the issue. I have attached the sample script i have…
Navin
  • 11
  • 1
  • 6
0
votes
4 answers

SQL - Convert to date

I have a numeric column in SQL which I need to convert to a date. The field is currently coming into the database as: "20181226.00000". I only need to the characters before the " . ". So i did a SUBSTRING - CHARINDEX looking for anything before the…