Follow via:
RSS
Email Alert
Question
0 Votes
+ -

SQL - Logic based record selection?

Hi all,

I'm trying to create a report in MS Visual Studio. I'm very new to VS and SQL in general and I've come across an issue I cannot work out for the life of me!

I have many columns in this report, however, I need a logic to govern the selection based on two of the columns; LOGI and MTYP.

I need my SQL statement to pull through all records with the following logic:

If LOGI = ' ' , select all records where MTYP = IN or DL
but if LOGI = 'L' select all records where MTYP = IN only

Note: LOGI is either ' ' (blank, not null) or 'L'. MTYP has other values than the values listed.

Any ideas?

Many thanks,

Mike
27th Jan 2011

Answers (1)

1 Vote
+ -
Chosen Answer
SQL - Logic based record selection?
SELECT * FROM TableName
WHERE (LOGI=' ' AND (MTYP = 'IN' OR MTYP = 'DL'))
OR
WHERE (LOGI='L' AND MYTP='IN')
ORDER BY LOGI, MYTP
Updated - 27th Jan 2011
Answer the question
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.