sql - How to sort by varchar field containing a date in ascending order -


in design time have given [dojingovrservice] field varchar datatype.
when trying order parameter(dojingovrservice) in ascending order not giving desired result.
know datatype problem can't change datatype data entered.

select ed.class,         ed.currentofficeplace,         ed.dob,         ed.dojincurrentoff,         ed.dojingovrservice,         ed.dojinsamvarg,         ed.empname,         ed.homeplace, ed.qualification  tbl_emplyeesbiodata ed order dojingovrservice asc 

date entered in format dd-mm-yyyy (i.e. 28-08-2004).

please me

this 1 of many reasons why should always use appropriate data types.
when have data in table, can change data type using alter table ddl statement:

alter table tablename alter column columnname datetime2; 

however, should copy table first , try alter on copy, if messes data not risk anything.
if alter successful on live table. if not, can go different approach, involving these stages:

  1. rename dojingovrservice column dojingovrservice_old. use sp_rename.
  2. add column dojingovrservice correct datatype (datetime2), using alter table ddl stement.
  3. update new dojingovrservice column values in dojingovrservice_old. need use convert.
  4. drop dojingovrservice_old column using alter table ddl statement.

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -