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:
- rename
dojingovrservice
columndojingovrservice_old
. usesp_rename.
- add column
dojingovrservice
correct datatype (datetime2), usingalter table
ddl stement. - update new
dojingovrservice
column values indojingovrservice_old
. need useconvert
. - drop
dojingovrservice_old
column usingalter table
ddl statement.
Comments
Post a Comment