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
1
vote
4 answers

Explicit conversion from data type date to bigint is not allowed

This used to work with a column type of DATEIME but now it won't with DATE. CONVERT(BIGINT,ev.StartDate) * -1 Is there anyway to get a BIGINT value from a DATE column?
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
1
vote
1 answer

Joining together 2 converted text fields

Struggling to join two text fields ,RTRIM(LTRIM(REPLACE(IM.ITEMDESC,',',''))) AS ITEMDESCR ,RTRIM(LTRIM(ISNULL(REPLACE(REPLACE(convert(varchar(MAX),[TXTFIELD]), CHAR(13),' '),',',''),''))) AS EXTRADESCRIPTION Had to remove the carriage return on…
Jamie hampson
  • 57
  • 1
  • 7
1
vote
2 answers

MSSQL Handle/Split Unknown Date String Format

Server Type: MSSQL 2014 My string(s): VARCHAR '2/05/2017 7:54:51 PM' I need to convert that to any supported DateTime format (or preferably directly to epoch). It needs to handle NULL and "" (blank) rows. I've spent a good few hours trawling answers…
Shane A.
  • 13
  • 4
1
vote
1 answer

Is CONVERT non-deterministic?

I have the following table: CREATE TABLE Portfolio.DailyStats ( Date date NOT NULL PRIMARY KEY, NAV int NOT NULL, SP500 decimal(8,4) NULL, R2K decimal(8,4) NULL, NetExp decimal(8,4) NULL, GrossExp decimal(8,4) NULL, [YrMn] AS…
1
vote
1 answer

Postgresql equivalent for SQL Server function Convert

I am in need of a Postgres function which is equivalent to SQL Server function convert. I ended up writing a function CREATE OR REPLACE FUNCTION convert (target VARCHAR(50),source ANYELEMENT,style INT) RETURNS ANYELEMENT AS $$ BEGIN …
Priya
  • 1,096
  • 4
  • 15
  • 32
1
vote
1 answer

What is SQL Sever's default format for converting dates from strings

I'm trying to work with a 3rd party application which stores dates (can be entered by the user, in some cases with little validation) in a varchar column, then uses CONVERT( DATETIME, MY_COLUMN ) - without an explicit format - when it wants to use…
aucuparia
  • 2,021
  • 20
  • 27
1
vote
3 answers

How to get date time 01/03/2017 16:06:21 AM format in SQL Server

I am working on a query in SQL server 2012 where I need to get datetime format as 01/03/2017 16:06:21 AM. How do I do that?
toby
  • 59
  • 4
1
vote
1 answer

Unable to generate tables after using convert for data transfer from XML to SQL Server

I am a little new at this so please bear with me. I am attempting to generate tables from an xml document. Due to some of the contents of the XML document I had to use the convert method, which I am not very familiar with. As a result I get an…
ana ng
  • 107
  • 2
  • 8
1
vote
1 answer

Using CASE and SELECT from another table using CONVERT

I'm working on SQL Server and I need help with a query. This is the scenario: I have 2 Tables Roster and Customer. PK [ID] exists in both Tables. CREATE TABLE [dbo].[Tbl_Roster_Test]( [CONCATENATE_NUMBER] [varchar](100) NOT NULL, …
Luis Lara
  • 75
  • 2
  • 9
1
vote
2 answers

JOIN on a String After Converted to Integer

I am trying to LEFT JOIN on a CHAR after it is converted to an INT. Like this: SELECT o.title, d.title FROM original o LEFT JOIN directory d ON CONVERT(o.directory_index, UNSIGNED INT) = d.index This gives me the correct response if the index is…
Bryan
  • 14,756
  • 10
  • 70
  • 125
1
vote
2 answers

SQL Date-Time Conversion with nested converts experiences random conversion errors

Looking for assistance with a strange issue if anyone has ideas: I have a SQL that statement works most of the time in a T-SQL script but crashes occasionally. I have identified the data that a crash occurs on and cannot identify any difference…
sallou
  • 99
  • 9
1
vote
3 answers

Error converting Sum[Field] as numeric or float

I am using a function to get total of a column field is : ALTER FUNCTION [dbo].[GetTwoWeeklyWorkTime](@EmployeeID as int,@PayPeriodID as varchar(10)) RETURNS int AS BEGIN DECLARE @StartDate DATETIME DECLARE @EndDate DATETIME Select…
user3590485
  • 241
  • 1
  • 9
  • 19
1
vote
3 answers

how to solve Passing DateTime value to paramaterized query Error

here is my query string SELECT Payment ,Balance ,PatientNo FROM [GP_DB].[dbo].[GP] where GP.GPDate= (SELECT CONVERT(VARCHAR(24),@GPDate,103)) GPDate is a Date type column, not…
donata
  • 43
  • 6
0
votes
2 answers

convert bigint to nvarchar by format

How can I convert bigint to nvarchar using the following scheme: 1 converts to 0001 123 converts to 0123
Ehsan
  • 3,431
  • 8
  • 50
  • 70
0
votes
1 answer

Need to convert column to datetime

I'm trying to convert an entire column to datetime in BigQuery. I had to bring it into SQL as string because datetime kept throwing errors. The current format of my data is Row date_hour 1 4/12/2016 3:00:00 AM 2 4/12/2016 4:00:00 AM 3 …