I have table as you can see below. The full query what i created is on this link on sqlfiddle table with all days. In query i use concat function for preparing query for PIVOT table with dates like column name and assing to variable @sql. The result you can see below in result1, this table will be subtable of another query and in next concat function i prepare statement which will compare dates between them "if the prices are same so the value will 0 in other way it will be 1" and assing to variable @sql2 (result2). With this query on table with all days everything works, but when i will delete for example date '2014-02-05' from that table it doesn't work as you can see in another link table with deleted date. I know i can write WHERE statement but i need it dynamicaly (because i don't know which date will be missed. Maybe if you know better solution you can write it me too. Thanks for your help
id name date price
------------------------------------
|1 | 'produkt1'| '2014-02-01'| 1250|
|2 | 'produkt1'| '2014-02-02'| 1250|
|3 | 'produkt1'| '2014-02-03'| 1210|
|4 | 'produkt1'| '2014-02-04'| 1230|
|5 | 'produkt1'| '2014-02-05'| 1230|
|6 | 'produkt1'| '2014-02-06'| null|
|7 | 'produkt1'| '2014-02-07'| 1230|
|8 | 'produkt1'| '2014-02-08'| 1230|
|9 | 'produkt2'| '2014-02-01'| 1350|
|10| 'produkt2'| '2014-02-02'| 1220|
|11| 'produkt2'| '2014-02-03'| 1240|
|12| 'produkt2'| '2014-02-04'| 1240|
|13| 'produkt2'| '2014-02-05'| 1240|
|14| 'produkt2'| '2014-02-06'| null|
|15| 'produkt2'| '2014-02-07'| null|
|16| 'produkt2'| '2014-02-08'| 1240|
result1 - PIVOT TABLE
name | 2014-02-01 | 2014-02-02 | 2014-02-03 | 2014-02-04 | 2014-02-05 | 2014-02-06 |
-----------------------------------------------------------------------------------------
produkt1 | 1250 | 1250 | 1210 | 1230 | 1230 | null
-----------------------------------------------------------------------------------------
produkt2 | 1350 | 1220 | 1240 | 1240 | 1240 | null
result2 - Comparing prices
name | 2014-02-01 <> 2014-02-02 | 2014-02-02 <>2014-02-03 | 2014-02-03 <> 2014-02-04| ..
-----------------------------------------------------------------------------------------
produkt1 | 1 | 0 | 0
-----------------------------------------------------------------------------------------
produkt2 | 0 | 0 | 1