Jump to content
Sign in to follow this  
peted

SQl Statment help

Recommended Posts

id

name

status

a

b

c

e

F

1

Jon

open

1

1

2

2

 

2

Jane

open

2

2

2

1

1

3

Billy

open

2

2

2

 

 

4

Mary

closed

 

2

2

2

 

5

James

Closed

1

2

 

2

2

6

Jimmy

Closed

 

 

 

2

1

 

 

Hi, I need some help with some SQL. I need a statement that select a row that have a status of open or if it is closed, one of the columns A-F have a number 1 in it.

 

 So in the example table above I would need rows 1, 2, 3 selected as they are open and rows 5 & 6 as they are closed but have a 1 in the A-F columns.

 

Hope this makes sense. Any help would be great.

Share this post


Link to post
Share on other sites

This is simple logic. You want to return a row if:

  • Status is open
  • Status is closed and a is 1 or b is 1 or c is 1 or d is 1 or e is 1 or f is 1.

This translates to the following WHERE clause:

WHERE
  status = 'open' OR
  status = 'closed' AND (a = 1 OR b = 1 OR c = 1 OR d = 1 OR e = 1 OR f = 1)

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...