question

munnast avatar image
munnast asked

SQL query to include one column value for one condition and exclude other columns

I am learning writing T-SQL queries can any help me writing the query for below scenario I have columns im.mfg with values(R, K, I ,Z) and orderfill with values(O,X,T) and my output should include columns im.mfg = k and od.orderfill = O, im.mfg values(R,K,I,Z) WHERE orderfill values(X,T) and exclude im.mfg values (R,I,T) where orderfill = O Select im.MFG,od.orderfill,im.ITEMID from ORDER od left join ITEMS im on im.ITEMID = od.ITEMID where od.orderfilled! = 'O'
sqltsqlsqlserver
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
David Wimbush avatar image
David Wimbush answered
You can make a WHERE clause as complicated as you need. It's a comination of one or more True/False expressions that control which rows come out. You can do things like: WHERE (ColumnA = 1 and ColumnB = 'X') OR (ColumnA = 2 and ColumnB != 'Y') So build up your WHERE clause one step at a time and test it as you go along.
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.