Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Converting Datatype varchar

Status
Not open for further replies.

This2willpass

IS-IT--Management
Aug 21, 2015
12
0
0
US
Hi All,

I am using T-SQL I have a column (ColA)that has datetime format and I simply want to pull the next day but date only into ColB

ColA
3/12/2014 12:00AM
3/19/2014 12:00AM
ColB
3/13/2014
3/20/2014


I have been trying the command below but keep getting the error "Conversion failed when convertint the varchar value '03-03-2014' to data type int."

Convert (varchar(10), "StartDate", 110)+1 as Next Day

Any and all help is greatly appreciated. TIA





 
The error is, because you can't add 1 to a string and there is no impllicit conversion of '03-03-2014' - which is the result of the Convert - to an integer, so the + operator could be used.

First of all, you want a date, not a varchar(10), so your conversion is outright not what you want. Alos, to add to a date or datetime, you have the dateadd() function, where you can choose many dateparts from nanoseconds to years as the unit of what you add (or subtract), you don't use the + operator for adding.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top