Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
-- Order by date wise report problem
select
    liftingbirds, totalweight, avgweight, dcno,
    convert(varchar,liftingdate,103) as liftingdate
from
    k_LiftingEntryRecords
where
    dcno = @dcno
order by
    liftingdate desc

Here I am not getting order wise date report ...when I remove where condition dcno = @dcno, then it comes order wise date report...

SQL
select
    liftingbirds, totalweight, avgweight, dcno,
    convert(varchar,liftingdate,103) as liftingdate
from
    k_LiftingEntryRecords
order by
    liftingdate desc



other wise it's not come.. like
Posted
Updated 23-Dec-13 5:04am
v3
Comments
joginder-banger 23-Dec-13 8:37am    
your dcno=@dcno is does not match. so try to equal value.
Siva Hyderabad 23-Dec-13 8:42am    
it is equal with my procedure value
ZurdoDev 23-Dec-13 11:09am    
You do have order by so if it is not coming out the way you want there must be some other issue.
OriginalGriff 23-Dec-13 11:19am    
Psst! Look at the column names he is using... :laugh:
ZurdoDev 23-Dec-13 11:22am    
Ya, but he wanted it that way. At least that is how I read it.

1 solution

Um.
It is, you know...it's sorted exactly as you specified.
When you select this:
SQL
select
    liftingbirds, totalweight, avgweight, dcno,
    convert(varchar,liftingdate,103) as liftingdate
You are creating a new temporary Text based "column" called "liftingdate", which masks the original DateTime based version.
So when you do this:
SQL
order by
    liftingdate desc
You are specifying that the records should be returned in order of the new text "column" - and the sort is a text sort (character by character) as a result.
Try:
SQL
select
    liftingbirds, totalweight, avgweight, dcno,
    convert(varchar,liftingdate,103) as [lifting date]
from
    k_LiftingEntryRecords
where
    dcno = @dcno
order by
    liftingdate desc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900