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

SQL SERVER: How to Preserve "DateFormat" in Convert VARCHAR to Date with multiple Date formats

I have several columns of varchar(max) type that have either date or datetime data. I want to convert them to date type, which I know that I should use CONVERT function. Up to here is no problem! ISSUE at my hand is that the dates stored in each…
MeysaM
  • 21
  • 10
0
votes
2 answers

Avoid default date (Jan 1900) in sql server varchar column

I have a experience table in my sql sever database having following columns: exp_id int, u_id int , exp_jobtitle varchar(100), exp_company varchar(100), exp_startdate date, exp_enddate varchar(50), exp_working varchar(50), exp_description…
AnumR
  • 85
  • 1
  • 12
0
votes
3 answers

How to convert mm/dd/yyyy militarytime -> mm/dd/yyyy hh:mm:ss AM/PM

I'm using the following code and almost getting what I'm looking for: SELECT sdb.NAME AS DatabaseName ,COALESCE(CONVERT(VARCHAR(10), cast(max(bus.backup_finish_date) as date), 101) + ' ' + convert(varchar(12), max(bus.backup_finish_date), 108),…
John Waclawski
  • 936
  • 1
  • 11
  • 20
0
votes
0 answers

Conversion failed when converting date and/or time from character string - SQL Server SELECT INTO Temp Table

I am sure this question has been asked in different ways but I am at my wits end for some reason. I am performing a pretty straight forward SELECT INTO FROM statement which includes A WHERE on the date to be added but I cannot get the temporary…
user3496218
  • 185
  • 3
  • 5
  • 19
0
votes
1 answer

Format is not working in an old SQL Server version

I am using format in a stored procedure. My problem is that on the server the SQL Server version is old, and format() does not work. My use: FORMAT([Data], 'dd.MM.yyyy') where data is: 2008-10-31 00:00:00.000 How can I use convert() to obtain the…
S.over17
  • 199
  • 2
  • 2
  • 14
0
votes
2 answers

SQL Server Convert 01 December 2016 to date

How can one convert the string "01 December 2016" to a date type in SQL Server? CONVERT(date, '01 December 2016', 106) Expected date outcome "01 Dec 2016"
danny
  • 1,969
  • 3
  • 16
  • 26
0
votes
2 answers

CAST OR CONVERT or custom?

I have the following table strand which is ordered in ascending order except for the 1st value, Strand 3.1.1 3.1.1.1 3.1.1.2 3.1.2 3.1.2.1 3.1.2.2 3.10 # this should have been at the top most 3.2.1 3.2.1.1 ... ... 3.20 …
goonerboi
  • 309
  • 6
  • 18
0
votes
2 answers

I'm trying to convert a base 10 number in sql to base 2 / binary but what's being returned ins't ones and zero's

I'm just using some simple sql to try and get it working and then I will implement it into my program. So my code is below: select convert(varbinary(16), cast('63' as int))) My result from this query is 0x000003F which is not what I wanted, I was…
Jack Tyler
  • 509
  • 6
  • 18
0
votes
0 answers

Convert SQL query result to Datetime - Incorrect syntax

I want to convert the result of this query (string to DateTime) SET [something] = dbo.fn_GetProfileElement('WelcomeSent',PropertyNames,PropertyValuesString) FROM aspnet_Profile where aspnet_Profile.UserId = CTUsers.userid so I try this: SET…
atroul
  • 51
  • 1
  • 13
0
votes
1 answer

return rows from 30 days ago in sql tables

I want to fetch up rows of two tables from 30 days ago in sql but my date column is nvarchar and I cant convert it to date I tried several things but But did not receive any result and And always got an error this is my query and I send TodayTime…
MPERSIA
  • 187
  • 1
  • 15
0
votes
2 answers

SQL Server date time convert

I have a field in my database table called Month which holds its values as an INT it has the values 1 to 12 - I would like a way to convert 1 to read 1-11-2016 00:00:00 ie as a datetime field, 2 to read 1-12-2016 00:00:00, 3 to read 1-1-2017…
SagarH
  • 39
  • 3
0
votes
1 answer

Incorrect Syntax near 'b' and failed to convert date or time

I have 2 queries. The first one got an error message that it failed to convert date or time select a.ProductID, sum(a.Quantity) as Qty ,SUM (a.SubTotal) as Sub from TransactionDetail a join Transactions b on a.TransactionID = b.TransactionDate group…
fadoewae
  • 11
  • 3
0
votes
1 answer

Convert varchar to datetime and add seconds

I have two columns startDate (160812 - year, month, day) and startTime (112345 - hour, mimutes, seconts) with a varchar datatype my target is concatenate them and convert them into datetime. And I should added to them other column (duration - int)…
Kalkov
  • 39
  • 6
0
votes
3 answers

SQL Server : how to convert binary back to int

Admin of our IS stored 8 flags like '00010000' (only true and false) to SQL Server as binary(2). In this format data has values like '0x1000'. Is possible to convert this binary back to '00010000' ? Convert, Cast, Substring don't work.
0
votes
1 answer

SQL Query WHERE equals int or varchar without breaking?

There is an instance where the filters I have are being dynamically plugged into my SQL query and sometimes cannot tell prior if they are int or varchar. Is there a way to allow either with a CASE WHEN statement? In my table (ent for entity), the…
triplethreat77
  • 1,276
  • 8
  • 34
  • 69