Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

SQL Query Tuning

SQL Query Tuning

1) In the below query, I am trying to fetch Status only - 'A' or 'P'. But i am getting output with all the status available in the Table.

2) I have mentioned RxProName <> ICName. But still i am getting the Matching Values of both the columns.


select Member,Status,DOB,RxProName,ICName from dbo.VW_RxsToPrint
where	ICName like '%SC Med%'
or		ICName like '%NC Med%'
and		RTRIM(RxProName) <> RTRIM(ICName)
and		VW_RxsToPrint.Status in ('A','P')
order by VW_RxsToPrint.Status ASC

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

@Sameer2010, I was not aware that there is Operator Precendence. Thank you for the link !
Avatar of chokka

ASKER

Thank you lwadwell

select Member,Status,DOB,RxProName,ICName from dbo.VW_RxsToPrint
where  (   ICName like '%SC Med%'
or             ICName like '%NC Med%'   )
and            RTRIM(RxProName) <> RTRIM(ICName)
and            VW_RxsToPrint.Status in ('A','P')

Returns exact results