Click here to Skip to main content
15,879,326 members
Home / Discussions / Database
   

Database

 
QuestionFind the right SSMS Pin
Corporal Agarn8-Aug-14 1:53
professionalCorporal Agarn8-Aug-14 1:53 
AnswerRe: Find the right SSMS Pin
Richard Deeming8-Aug-14 2:18
mveRichard Deeming8-Aug-14 2:18 
GeneralRe: Find the right SSMS Pin
Corporal Agarn8-Aug-14 2:25
professionalCorporal Agarn8-Aug-14 2:25 
Questionsql server insert into select + in select part if else Pin
Karan_TN7-Aug-14 0:16
Karan_TN7-Aug-14 0:16 
AnswerRe: sql server insert into select + in select part if else Pin
Mycroft Holmes7-Aug-14 0:55
professionalMycroft Holmes7-Aug-14 0:55 
QuestionHow to change multiple date formats in Sql server Pin
AzeeM_R6-Aug-14 2:51
professionalAzeeM_R6-Aug-14 2:51 
AnswerRe: How to change multiple date formats in Sql server Pin
Corporal Agarn6-Aug-14 3:38
professionalCorporal Agarn6-Aug-14 3:38 
AnswerRe: How to change multiple date formats in Sql server Pin
Richard Deeming6-Aug-14 3:50
mveRichard Deeming6-Aug-14 3:50 
AzeeM_R wrote:
Conversion failed when converting the nvarchar value 'Apr 7 2014 4:42PM' to data type int

You shouldn't be trying to convert the data to an int. SQL has specific data types for storing date/time data[^], which you should be using instead.

The yyyy-MM-dd and MMM d yyyy h:mmTT formats are easy to convert:
SQL
SELECT
    Convert(date, '2014-05-01'),
    Convert(datetime2(0), 'Apr 7 2014 4:42PM')
;


The other two formats will be impossible to convert unless your data contains another field indicating whether they're dd/MM/yyyy or MM/dd/yyyy. Without that additional field, there would be no way to know whether 01/02/2014 should be 1st February or 2nd January.

If you do have an additional field indicating the format of the date, then your options depend on the version of SQL that you're using. SQL 2012 and 2014 have the PARSE method[^]:
SQL
SELECT
    PARSE('5/29/2014' As date),
    PARSE('16/4/2014' As date USING 'en-GB')
;

For older versions, you would need to write your own function to parse the string.



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


AnswerRe: How to change multiple date formats in Sql server Pin
Mycroft Holmes6-Aug-14 14:16
professionalMycroft Holmes6-Aug-14 14:16 
SuggestionRe: How to change multiple date formats in Sql server Pin
AzeeM_R11-Aug-14 8:14
professionalAzeeM_R11-Aug-14 8:14 
QuestionHandling Duplicate records Pin
Ambertje5-Aug-14 4:35
Ambertje5-Aug-14 4:35 
Questionsplit datatable column using c# Pin
Jaimin H. Soni4-Aug-14 22:31
Jaimin H. Soni4-Aug-14 22:31 
QuestionRe: split datatable column using c# Pin
Eddy Vluggen5-Aug-14 2:35
professionalEddy Vluggen5-Aug-14 2:35 
AnswerRe: split datatable column using c# Pin
Jaimin H. Soni6-Aug-14 1:12
Jaimin H. Soni6-Aug-14 1:12 
GeneralRe: split datatable column using c# Pin
Eddy Vluggen6-Aug-14 1:56
professionalEddy Vluggen6-Aug-14 1:56 
GeneralRe: split datatable column using c# Pin
Jaimin H. Soni6-Aug-14 2:00
Jaimin H. Soni6-Aug-14 2:00 
GeneralRe: split datatable column using c# Pin
Eddy Vluggen6-Aug-14 2:30
professionalEddy Vluggen6-Aug-14 2:30 
QuestionHelp with XML Pin
byka31-Jul-14 6:36
byka31-Jul-14 6:36 
GeneralRe: Help with XML Pin
PIEBALDconsult31-Jul-14 7:01
mvePIEBALDconsult31-Jul-14 7:01 
GeneralRe: Help with XML Pin
byka31-Jul-14 7:04
byka31-Jul-14 7:04 
AnswerRe: Help with XML Pin
Richard Deeming31-Jul-14 7:29
mveRichard Deeming31-Jul-14 7:29 
QuestionCannot create a foreign key reference (probably my fault) Pin
Richard MacCutchan31-Jul-14 0:38
mveRichard MacCutchan31-Jul-14 0:38 
AnswerRe: Cannot create a foreign key reference (probably my fault) Pin
Simon_Whale31-Jul-14 1:27
Simon_Whale31-Jul-14 1:27 
GeneralRe: Cannot create a foreign key reference (probably my fault) Pin
Richard MacCutchan31-Jul-14 1:36
mveRichard MacCutchan31-Jul-14 1:36 
AnswerRe: Cannot create a foreign key reference (probably my fault) Pin
Eddy Vluggen31-Jul-14 1:28
professionalEddy Vluggen31-Jul-14 1:28 

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.