sql - Greatest date from list of date -


i have simple data base:

7/2/2013

7/13/2013

i write simple sql statement select greatest date list of date. try use (max function) follow:

select max([p_date]) [baldb].[dbo].[tab_product] 

the result incorrect; gives me smallest date not greatest follow:

7/2/2013 

so please me know problem in sql statement , how can solve problem: greatest date list of date or compare local date , take greater!!

the sql max function returns largest value of selected column, in case since data type nvarchar largest value alphabetically larger, in case 7/2/2013 (since "2" greater "1" in "13").

what need @david mentioned, either chance data type of column or if isn't feasible can cast in query datetime

for example

select max(cast([p_date] datetime)) [baldb].[dbo].[tab_product] 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -