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 |
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2009-03-13 : 11:46:53
|
| I have 4 Stores. I want 55 stores, therefore, have to copy the data I have to make up to 50.I want to know how to calculate the number of times I have to copy the data. Each iteration, I will double the data:Iteration 1: 4+4 = 8Iteration 2: 8+8 = 16Iteration 3: 16+16 = 32Iteration 4: 32+32 = 64Answer = 4 iterationsHow can I calculate '4' in a nice and clean SQL statement (I'm rubbish at maths)?Thanks Hearty head pats |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-03-13 : 12:11:45
|
| Looks like your pattern is pretty simple. If x is the iteration then your formula would be 2^(2+x)Ex:Iteration 1: 2^(2+1) = 2^3 = 8Iteration 2: 2^(2+2) = 2^4 = 16Iteration 3: 2^(2+3) = 2^5 = 32Iteration 4: 2^(2+4) = 2^6 = 64etc.Hope that helps!Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-13 : 12:26:36
|
You double the data for each iteration.SELECT CEILING((LOG(@WantedRecordCount) - LOG(@InitialRecordCount)) / LOG(2)) AS IterationsNeeded E 12°55'05.63"N 56°04'39.26" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-13 : 12:27:45
|
SELECT CEILING((LOG(55) - LOG(4)) / LOG(2)) returns 4. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2009-03-13 : 12:46:34
|
| Thank you both for your efforts!!Peso, I knew you'd come through being the mathematician you are!But thanks again to you both!Hearty head pats |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-13 : 17:31:15
|
[code]SELECT CEILING(LOG(55) / LOG(2)) - FLOOR(LOG(4) / LOG(2))[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|