Im having a small problem. Hope someone can help me I would like to make an if statement, such that it uses two different tables, depending on the product name? (I have already made the below into a stored procedure, i understand that it's a stupid example with a static name, but hope you get my drift). My problem is that i don't understand, how i should do write the code, such that it understands that if the product name contains certain characters, it should look into a different table than tbSourceData?
[select pvt.Dates , pvt.1stProduct , pvt.2ndproduct , JR.discountd_prices from ( select Name, Dates, Prices from dbo.tbSourceData ) tb pivot ( max(Prices) for Name in (1stProduct, 2ndProduct) ) pvt left join tbSourceData JR on JR.Dates = pvt.Dates and JR.Name = '1stProduct' where pvt.Dates > getdate()-100]