Question Locked

SQL - Logic based record selection?

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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

2 replies

by n0chi

SELECT * FROM TableName
WHERE (LOGI=' ' AND (MTYP = 'IN' OR MTYP = 'DL'))
OR
WHERE (LOGI='L' AND MYTP='IN')
ORDER BY LOGI, MYTP

This discussion is closed to new replies.