|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Thursday, December 13, 2012 6:46 AM
Points: 72,
Visits: 224
|
|
Hi there,
Apologies for the elusive subject title. I'm trying to filter only rows on one field only when another field has a certain value.
I have a query with several columns. One column (called NAME) has only two values so to keep this simple for the question the values are
Paul Jim
This column will only ever have these two values for all the rows.
I have another column (called POSITION) that only ever has three values
Staff Manager Executive
I want to filter rows on another column that only applies to Paul.
For example
Where NAME is = to PAUL only include rows from POSITION where they are MANAGER.
If the NAME is Jim, the filter will not apply to POSITION.
I'm unsure how to achieve this filter without affecting rows where the NAME is Jim.
I hope this makes sense.
What would be the easiest way to do this on the WHERE clause?
Many thanks
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:10 PM
Points: 4,319,
Visits: 9,658
|
|
cidr (12/11/2012) Hi there,
Apologies for the elusive subject title. I'm trying to filter only rows on one field only when another field has a certain value.
I have a query with several columns. One column (called NAME) has only two values so to keep this simple for the question the values are
Paul Jim
This column will only ever have these two values for all the rows.
I have another column (called POSITION) that only ever has three values
Staff Manager Executive
I want to filter rows on another column that only applies to Paul.
For example
Where NAME is = to PAUL only include rows from POSITION where they are MANAGER.
If the NAME is Jim, the filter will not apply to POSITION.
I'm unsure how to achieve this filter without affecting rows where the NAME is Jim.
I hope this makes sense.
What would be the easiest way to do this on the WHERE clause?
Many thanks
WHERE (NAME = 'Paul' and POSITION = 'MANAGER') or NAME = 'Jim'
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, January 28, 2013 1:45 AM
Points: 386,
Visits: 199
|
|
where (name = 'Paul' and position = 'manager') or name = 'Jim'
Cursors never. DTS - only when needed and never to control.
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:10 PM
Points: 4,319,
Visits: 9,658
|
|
nigelrivett (12/11/2012) where (name = 'Paul' and position = 'manager') or name = 'Jim'
?? looks remarkably like a lowercase version of my solution
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, January 28, 2013 1:45 AM
Points: 386,
Visits: 199
|
|
Yep - odd. Yours wasn't visible when I typed mine in but from the post dates they are 20 mins apart.
No they are 1 min apart - sorry I didn't predict that you were going to post that while I was typing.
Cursors never. DTS - only when needed and never to control.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Thursday, December 13, 2012 6:46 AM
Points: 72,
Visits: 224
|
|
Thanks guys, I tried this previously but it wasn't working for me because the actual solution uses the IN statement for NAME as there's three values to be pulled through. I removed IN and used '=' for each value in the WHERE clause, works now.
Thanks
|
|
|
|