SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 result data order different
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chbala85
Starting Member

49 Posts

Posted - 02/25/2014 :  01:11:36  Show Profile  Reply with Quote
Select CONVERT(VARCHAR(10), enrolldate, 101) AS enrolldate,lastname ,firstname, LongDesc,Patsource,response,memberId, Case ins2 when 1 then 'Level 1' when 2 then 'Level 2' when 3 then 'Level 3' when 4 then 'Level 4' else '' end ins2,isnull(CONVERT(VARCHAR(10), DisenrolledDate, 101),'') AS DisenrolledDate From patients P , patientforms PF , Referral R ,qualifiedtype QT, (Select MAX(patientforms.patientFormId)PFID from patientforms , Referral where completed =1 and patientForms.patientFormId = Referral.patientFormId and Referral.questionId = 10829 and Referral.responseKeyDetailId = 13198 group by patientId ) SelectedPFID Where R.patientFormId = SelectedPFID .PFID And R.questionId = 10829 and R.responseKeyDetailId = 13198 And P.patientId = PF.patientId And SelectedPFID.pfid = Pf.patientFormId And QT.qualifiedTypeId = P.qualified



Select CONVERT(VARCHAR(10), enrolldate, 101) AS enrolldate,lastname ,firstname, LongDesc,Patsource,response,memberId, Case ins2 when 1 then 'Level 1' when 2 then 'Level 2' when 3 then 'Level 3' when 4 then 'Level 4' else '' end ins2,isnull(CONVERT(VARCHAR(10), DisenrolledDate, 101),'') AS DisenrolledDate From patients P , patientforms PF , Referral R ,qualifiedtype QT, (Select MAX(patientforms.patientFormId)PFID from patientforms , Referral where completed =1 and patientForms.patientFormId = Referral.patientFormId and Referral.questionId = 10829 and Referral.responseKeyDetailId = 13198 group by patientId ) SelectedPFID Where R.patientFormId = SelectedPFID .PFID And R.questionId = 10829 and R.responseKeyDetailId = 13198 And P.patientId = PF.patientId And SelectedPFID.pfid = Pf.patientFormId And QT.qualifiedTypeId = P.qualified


hi all,
i have 2 queries but both queries are same and data also getting same records.
if run two queries the result records order is different.

why the result data order is different.

please help me.



kennejd
Starting Member

USA
11 Posts

Posted - 02/26/2014 :  12:50:14  Show Profile  Reply with Quote
Not sure what would cause that...maybe a new index was added? Were the queries ran against different servers...one on a production server, one against a report server? The queries do look the same.
Go to Top of Page

maunishq
Yak Posting Veteran

Canada
71 Posts

Posted - 02/26/2014 :  12:59:58  Show Profile  Reply with Quote
Yes, it is possible. It is called Non Deterministic property. The order of data is not fixed unless it is specified by ORDER BY clause. So if you want the same order for both queries, add ORDER BY clause to both of them.

!_(M)_!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/27/2014 :  02:43:35  Show Profile  Reply with Quote

quote:
Originally posted by chbala85

Select CONVERT(VARCHAR(10), enrolldate, 101) AS enrolldate,lastname ,firstname, LongDesc,Patsource,response,memberId, Case ins2 when 1 then 'Level 1' when 2 then 'Level 2' when 3 then 'Level 3' when 4 then 'Level 4' else '' end ins2,isnull(CONVERT(VARCHAR(10), DisenrolledDate, 101),'') AS DisenrolledDate From patients P , patientforms PF , Referral R ,qualifiedtype QT, (Select MAX(patientforms.patientFormId)PFID from patientforms , Referral where completed =1 and patientForms.patientFormId = Referral.patientFormId and Referral.questionId = 10829 and Referral.responseKeyDetailId = 13198 group by patientId ) SelectedPFID Where R.patientFormId = SelectedPFID .PFID And R.questionId = 10829 and R.responseKeyDetailId = 13198 And P.patientId = PF.patientId And SelectedPFID.pfid = Pf.patientFormId And QT.qualifiedTypeId = P.qualified



Select CONVERT(VARCHAR(10), enrolldate, 101) AS enrolldate,lastname ,firstname, LongDesc,Patsource,response,memberId, Case ins2 when 1 then 'Level 1' when 2 then 'Level 2' when 3 then 'Level 3' when 4 then 'Level 4' else '' end ins2,isnull(CONVERT(VARCHAR(10), DisenrolledDate, 101),'') AS DisenrolledDate From patients P , patientforms PF , Referral R ,qualifiedtype QT, (Select MAX(patientforms.patientFormId)PFID from patientforms , Referral where completed =1 and patientForms.patientFormId = Referral.patientFormId and Referral.questionId = 10829 and Referral.responseKeyDetailId = 13198 group by patientId ) SelectedPFID Where R.patientFormId = SelectedPFID .PFID And R.questionId = 10829 and R.responseKeyDetailId = 13198 And P.patientId = PF.patientId And SelectedPFID.pfid = Pf.patientFormId And QT.qualifiedTypeId = P.qualified


hi all,
i have 2 queries but both queries are same and data also getting same records.
if run two queries the result records order is different.

why the result data order is different.

please help me.






I dont see any ORDER BY being used. So far as you dont have an ORDER BY in query you're selecting only random records. there's no concept of default ordering of a resultset so order that you see depends on whole lot of factors and can be regarded only as random until you use ORDER BY

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000