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 |
|
laura_se
Starting Member
3 Posts |
Posted - 2009-09-15 : 12:21:07
|
| I'm completely stuck...here's what I am trying to accomplish:I have a table with groups of information ie...Bit1 1Bit2 0Bit3 1Bit4 0Bit1 1Bit2 0Bit3 1Bit4 0Bit1 0Bit2 0Bit3 0Bit4 0They are grouped together in groups of four (Bit1-4)...if the group is the same as the one before it...delete it...if not...leave it and move past it.So in the above case the final output should be:Bit1 1Bit2 0Bit3 1Bit4 0Bit1 0Bit2 0Bit3 0Bit4 0I've tried using SQL cursor, using sql top, and even some if statements...so far I have been unsuccessful! Any help would be much appreciated!!! |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-15 : 12:39:32
|
That cannot be all.Assume that there is a table with columns [which_bit] and [bit_value]there is more information needed to select the right grouping and the right order. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
laura_se
Starting Member
3 Posts |
Posted - 2009-09-15 : 16:22:52
|
| Their is an additional column...dateTime. I just need SQL to take the first four lines and compare them to the next four...if they are the same delete one set...if they are different make that the comparison block. I always code in C# and don't know much about SQL :( I had a new idea that might work...but I'm not totally there...I can take the first four rows and put them in a seperate table...take the next four rows and put them in a different table. Then I could compare table 1 to table 2. I have the SQL logic almost there for this...I just don't know how to make an IF statement evaluate a variable value or boolean in SQL.I have...IF (SELECT * FROM table1 1 INNER JOIN table2 2ON 1.dateTime = 2.dateTimeAND 1.bit_value = 2.bit_value = null)--move to the next lineELSE--I have all this logic figured out.I need the if statement to evaluate true or false :( |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-16 : 06:24:50
|
| Use 2 temp tablesI would use a temporary table for everything ever |
 |
|
|
laura_se
Starting Member
3 Posts |
Posted - 2009-09-16 : 08:47:24
|
| yes I was thinking of using temp tables...but the problem is not the tables...it's the comparing statement...the one I posted doesn't work and I don't know how to tell the database (in SQL) to compare all the fields in table a to all the fields in table b |
 |
|
|
|
|
|