December 9, 2009 at 12:46 am
Hi
I clarify me in Order by causal
DECLARE @TEMP1 TABLE (IDS INT,Date datetime)
DECLARE @DATE1 DATETIME
SET @DATE1=GETDATE()
INSERT INTO @TEMP1 SELECT 4029,@DATE1
INSERT INTO @TEMP1 SELECT 9841,@DATE1
INSERT INTO @TEMP1 SELECT 11463,@DATE1
INSERT INTO @TEMP1 SELECT 15293,@DATE1
INSERT INTO @TEMP1 SELECT 185,@DATE1
Select * from @TEMP1
Select Top 5 * from @TEMP1 ORDER BY Date
Select Top 5 * from @TEMP1 ORDER BY Date desc
Select * from @TEMP1 ORDER BY Date
why if i specify Order by date in top it is returning differently
even though specify "Desc" it is returning differently
give me tips on this
Thanks
Parthi
Thanks
Parthi
December 9, 2009 at 1:40 am
What do you mean by 'returning differently'? Bear in mind that all 5 rows have exactly the same value for the Date column, so in this case, any order of the returned rows is fine, it's only the order by Date (which is the same) that's guaranteed.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 9, 2009 at 2:17 am
Hi thanks
I am asking this because in a table i am having the same record and i am returning the value from that table If it is 2nd time called i have to take them depending on the status flag.
While 2nd time i have to use order by date Asc depending on the status flag, thats why i am asking
Thanks
Parthi
December 9, 2009 at 5:59 am
Sorry, don't understand. Table structure, sample data and some details on what should be returned when and how would be useful.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply