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.
| Author |
Topic |
|
magikminox
Starting Member
27 Posts |
Posted - 2008-06-11 : 06:37:16
|
| Hi guysI have a table that stores records and each receord has a default logflag value of 0.Each time any record is changed,a new record is inserted with similar vaues but logflag flag remains 0.The original record that was modified will is kept but will have its log flag set to 1.Now i want to display the two records in a report one on top of the other so that users can clearly see what chages were made for audit purposes.How do i do my select statement so that for each record that was modified,the original one(logflag 1) is displayed and the new modified one(logflag 0 ) is also displayed just below it.ieid name email address city logflag modifieddate23 rob rob@me.com oxford lane wolverton 1 20/6/200823 rob robe@me.com huge road burnside 0 nullThe same should be done for all the modified records.When a record is has not been modified,it should not be displayed by the select statement.Thanks in advanceIn god we trust,everything else we test. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-11 : 07:00:01
|
| SELECT * FROM Table ORDER BY id ASC,CAST(logflag as int) DESC |
 |
|
|
magikminox
Starting Member
27 Posts |
Posted - 2008-06-11 : 09:18:58
|
| thanks for the quick response.my issue now is how do i filter only id numbers with both a flag of 0 and 1In god we trust,everything else we test. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-11 : 09:50:15
|
| Select id from your_table group by idhaving min(flag)=0 and max(flag)=1MadhivananFailing to plan is Planning to fail |
 |
|
|
magikminox
Starting Member
27 Posts |
Posted - 2008-06-12 : 04:33:08
|
| thanks a lot.my problem is solvedIn god we trust,everything else we test. |
 |
|
|
|
|
|