Click here to Skip to main content
15,887,027 members
Home / Discussions / Database
   

Database

 
GeneralRe: Linq-ToSQL Invalid Cast Pin
Kevin Marois2-Feb-17 7:31
professionalKevin Marois2-Feb-17 7:31 
QuestionHow to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu30-Jan-17 19:53
professionalTarunKumarSusarapu30-Jan-17 19:53 
AnswerRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Peter Leow30-Jan-17 20:23
professionalPeter Leow30-Jan-17 20:23 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu30-Jan-17 20:29
professionalTarunKumarSusarapu30-Jan-17 20:29 
AnswerRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Peter Leow30-Jan-17 20:46
professionalPeter Leow30-Jan-17 20:46 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Chris Quinn31-Jan-17 0:33
Chris Quinn31-Jan-17 0:33 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu31-Jan-17 1:07
professionalTarunKumarSusarapu31-Jan-17 1:07 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Richard Deeming31-Jan-17 2:29
mveRichard Deeming31-Jan-17 2:29 
Which means one of the strings in the source column is not a valid datetime value.

Which is why you should never store dates as strings. Smile | :)

If you're using SQL 2012 or later, you could use TRY_CONVERT[^] or TRY_PARSE[^], which will return NULL for any values it can't convert. Otherwise, you're stuck with converting the values manually.

NB: In your example, you should update the new GL_DATE1 column directly, rather than updating the original GL_DATE column and then trying to copy it across.

You'll probably also want to use the newer datetime2 type[^], which has a better range than the old datetime type.

SQL
alter table GL add GL_DATE1 datetime2(0) null;
update GL set GL_DATE1 = TRY_CONVERT(datetime2(0), getdate(), 104);
select GL_DATE from GL where GL_DATE1 Is Null And GL_DATE Is Not Null;




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer



modified 1-Feb-17 7:58am.

GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu1-Feb-17 18:09
professionalTarunKumarSusarapu1-Feb-17 18:09 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Richard Deeming2-Feb-17 2:04
mveRichard Deeming2-Feb-17 2:04 
QuestionUsing Pooling or SqlConnection object variable is better ? Pin
MrKBA24-Jan-17 22:43
MrKBA24-Jan-17 22:43 
AnswerRe: Using Pooling or SqlConnection object variable is better ? Pin
Tim Carmichael25-Jan-17 2:31
Tim Carmichael25-Jan-17 2:31 
GeneralRe: Using Pooling or SqlConnection object variable is better ? Pin
MrKBA25-Jan-17 20:30
MrKBA25-Jan-17 20:30 
AnswerRe: Using Pooling or SqlConnection object variable is better ? Pin
Richard Deeming25-Jan-17 3:26
mveRichard Deeming25-Jan-17 3:26 
GeneralRe: Using Pooling or SqlConnection object variable is better ? Pin
MrKBA25-Jan-17 20:29
MrKBA25-Jan-17 20:29 
GeneralRe: Using Pooling or SqlConnection object variable is better ? Pin
Richard Deeming26-Jan-17 1:38
mveRichard Deeming26-Jan-17 1:38 
GeneralRe: Using Pooling or SqlConnection object variable is better ? Pin
MrKBA26-Jan-17 1:39
MrKBA26-Jan-17 1:39 
QuestionRegularExpressions in SQL Server Pin
indian14323-Jan-17 12:50
indian14323-Jan-17 12:50 
AnswerRe: RegularExpressions in SQL Server Pin
Richard MacCutchan23-Jan-17 21:52
mveRichard MacCutchan23-Jan-17 21:52 
AnswerRe: RegularExpressions in SQL Server Pin
Richard Deeming24-Jan-17 2:29
mveRichard Deeming24-Jan-17 2:29 
QuestionSQl, Oracle Database Pin
Member 1295956019-Jan-17 23:59
Member 1295956019-Jan-17 23:59 
SuggestionRe: SQl, Oracle Database Pin
ZurdoDev24-Jan-17 3:20
professionalZurdoDev24-Jan-17 3:20 
QuestionJOIN Problem Pin
Kevin Marois19-Jan-17 9:01
professionalKevin Marois19-Jan-17 9:01 
AnswerRe: JOIN Problem Pin
ZurdoDev19-Jan-17 9:22
professionalZurdoDev19-Jan-17 9:22 
GeneralRe: JOIN Problem Pin
Kevin Marois19-Jan-17 9:25
professionalKevin Marois19-Jan-17 9:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.