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
334
votes
24 answers

How to convert DateTime to VarChar

I need to convert a value which is in a DateTime variable into a varchar variable formatted as yyyy-mm-dd format (without time part). How do I do that?
Ali
  • 5,499
  • 7
  • 25
  • 28
16
votes
10 answers

Custom Date/Time formatting in SQL Server

I am trying to write a stored procedure which selects columns from a table and adds 2 extra columns to the ResultSet. These 2 extra columns are the result of conversions on a field in the table which is a Datetime field. The Datetime format field…
Pascal
  • 4,127
  • 8
  • 33
  • 29
4
votes
0 answers

Convert_tz function in SQL Server

In MySQL there is function called CONVERT_TZ(dt,from_tz,to_tz) which converts one timezone to another timezone -Reference-. I had used CONVERT(datetime,SWITCHOFFSET(CONVERT(datetimeoffset,getdate()),'+05:30')) this function is taking "+00:00"…
NHD
  • 435
  • 1
  • 6
  • 17
3
votes
3 answers

How to convert varchar(4) to float in SQL Server 2008?

I'm trying to convert my database fields from VARCHAR(4) to FLOAT. Some of the values in these fields might not be digits since these fields didn't have any validation prior. My main target is to convert any integer or decimal value in float format…
espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
3
votes
3 answers

How do I get the date from a datetime when creating a SQL view?

I have searched for hours and found a lot of information about how do convert a datetime field to a date. All of it works well in my SQL window. However, the minute I try to use in in a view it crashes. Version: SQL Server v17.0 Example: field in…
C.Smith
  • 31
  • 1
  • 2
3
votes
2 answers

SQL Convert(Date + Year(Date)) in Someone Else's Code

I have a SQL view, that as far as I understand, attempts to get the latest invoice date and the year and month combination of that invoice date. These values are then used to count the quantity in that month. My SQL knowledge is basic and I'm not…
Jak
  • 471
  • 5
  • 20
3
votes
1 answer

why these is a question mark at the end of string

i want to get a string like [www.myweb.com?q=id%3D123456%26action%3Dgo​] but actually i get [www.myweb.com?q=id%3D123456%26action%3Dgo?​] It ends up with a question mark. My data engine is SQL server 2012 declare @id bigint; set…
Benny Ae
  • 1,897
  • 7
  • 25
  • 37
3
votes
1 answer

Using Convert on an ELSE CASE SQL query

I am performing a SQL query in Postgres, which selects a numeric field. I need to display a string value as the result of this SELECT, so I am using a CASE statement like this: Select case numeric_field when 100 then 'some string' when 200 then…
CarlosJavier
  • 1,005
  • 1
  • 16
  • 29
3
votes
2 answers

Copying data from PostgreSQL to MySQL

I currently have a PostgreSQL database, because one of the pieces of software we're using only supports this particular database engine. I then have a query which summarizes and splits the data from the app into a more useful format. In my MySQL…
bdx
  • 3,316
  • 4
  • 32
  • 65
2
votes
1 answer

how to prevent convert big numbers as varchar example 1444092 is 1.44409e+006

this is my final query select Codigo, Indicador, case when Indicador like '%Porcentaje%' then cast((round((([Valor Censo Elegido]/@cantidad)*100),0)) as varchar(50))+' %' else cast([Valor Censo Elegido]as varchar(50)) end as [Valor Censo…
angel uc
  • 279
  • 2
  • 8
  • 21
2
votes
2 answers

SQL, CONVERT, CAST Data Type?

I am not sure how to use either CAST or CONVERT in this script. SQL says: Conversion failed when converting the varchar value 'Amazing' to data type int. Can someone please tell me how to do this? USE AdventureWorks2012 GO DECLARE @Number01…
Shrikesh
  • 41
  • 2
2
votes
1 answer

Convert dd/mm/yyyy to date in SQL Server

I'm going nuts trying to convert a string type column into date. The column name is StartDate, which contains a string date format dd/mm/yyyy. The field type is varchar(3000). I tried the following: CONVERT(datetime, StartDate,…
inbal_bpr
  • 73
  • 2
  • 3
  • 9
2
votes
2 answers

Converting varchar values to decimal while handling NULLs and EMPTY strings as 0

I have a column of varchar datatype populated with a mix of values such as 1.2, 5.33 while also having NULLs and EMPTY strings. I want to convert all the values to decimal while treating NULLs and EMPTY strings as 0. I can change the NULLs or EMPTY…
user2307236
  • 665
  • 4
  • 19
  • 44
2
votes
4 answers

TSQL Convert VARCHAR of HHMMSS to TIME

I have a VARCHAR field that has sample values as listed below and I would like to convert it to HH:MM:SS. Suggestions? 151200 085800 080100 210100 083300
C Layne
  • 33
  • 2
  • 7
2
votes
2 answers

Retain the column name when you convert() in SQL

If I have the SQL query: select project.Employee, project.HoursQuantity, convert(varchar(10), project.EntryDate, 120) from db.Project as project It will return ProjectHours and HoursQuantity with the proper column name, but will return…
Jake Steele
  • 305
  • 3
  • 13
1
2 3 4 5 6 7