Dear all, I need a TSQL statement to find the difference of values of two rows in the same table, by taking into consideration some conditions.
I have the following rowss in a table named table1
dbname sqlinst size1 ddate
sqldb1 inst1 200 1/1/2009
sqldb1 inst1 250 1/1/2010
sqldb1 inst1 170 1/1/2008
sqldb2 inst2 300 1/1/2009
sqldb2 inst2 340 1/1/2010
I need to find the difference between size1 values, for columns where their dbname and sqlinst are the same.
I also need to define in TSQL that the ddate of row from where I subtract (size1) from is 1/1/2010 and that the ddate of the row I subtract (size1) is 1/1/2009 (e.g. in the above example: for sqldb1 inst1, I need to perform 250-200 and ignore 170, and for sqldb2
Please let me know if you have a solution for this.
A million thanks!
View Complete Post