Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I am not that familiar with SQL.I need to write a query that will select different columns form different tables, based on the outcome of an IF statement.Something like:IF(Table1.TargetType = 'some_value')SELECT Table1.Date, Table2.ItemFROM Table1 INNER JOIN Table2 ON Table1.DocKey = Table2.DocKeyELSESELECT Table3.Date, Table4.ItemFROM Table1 INNER JOIN Table3 ON Table1.TargetKey = Table3.DocKey INNER JOIN Table4 ON Table3.DocKey = Table4.DocKeyODRER BY Date;How can I achieve this?
Thanx for your reply.What I needed was to list sales orders and invoices in the same query.I found an alternative solution - I used a WHERE clause to copy the sales orders and invoices i needed to a temp table, then I used a standard SELECT statement to retrieve the data.Thanx anyway.