Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT DISTINCT MG.IDNO   ,MG.LOANUMBER,MG.PERIOD  ,MG.YEAR1 ,
          MG.TX_DATE,MG.TY_DATE  ,MG.ACCRUED ,MG.SACCRUED,
          MG.OPENING,MG.PAYMENT  ,MG.INTEREST,MG.REPAY,MG.CLOSING,
          L.CUSTOMER,(MG.IDNO+''+MG.LOANUMBER) AS IDNOLOAN
  FROM MGBALANCE MG
  LEFT  JOIN LOANS L
  ON MG.IDNO=L.IDNO
  WHERE MG.IDNO= @ZIDNO AND
  CONVERT(NVARCHAR, MG.YEAR1) + Right('00' +  Convert(varchar(10), MG.PERIOD), 2)  BETWEEN @STAT AND @END
  ORDER BY   MG.IDNO,MG.LOANUMBER,CONVERT(NVARCHAR,MG.YEAR1) + Right('00' +  Convert(varchar(10),MG.PERIOD), 2),TX_DATE



Have the above error message when I introduced the 'DISITNCT' syntax.

Please rectify the problem above.

Thanks

What I have tried:

Checked my earlier codes and the interner
Posted
Updated 17-Jul-16 5:27am
v3

1 solution

The error is fairly clear, if you think about it: You cannot use SELECT DISTINCT unless all of the items in the ORDER BY clause are included in the SELECT.
Why not? Well if you don't, which items are distinct? There may be multiple rows in the ORDER BY which are different, but which aren't DISTINCT unless all the ordering columns are present - so which should SQL choose to discard? It doesn't want to make that decision - because it really hates giving you the wrong info - so instead it passes the buck back to you to change your query so that distinct means distinct! :laugh:
 
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