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 |
|
jmaikido
Starting Member
2 Posts |
Posted - 2008-09-08 : 00:50:44
|
| Hi Listers,I'm kinda stuck on providing a code solution to the following:Any help wld b greatly appreciated.I have a table with 4 columns:HoleID, mFrom, mTo, CodeEssentially, where i have irregular intervals, ie. < 1m (between mfrom & the next mTo), i wish to insert a new record that pads-out the interval to the nearest whole number and also incorporates the same code.eg. Existing data:HoleId mFrom mTo CodeTWDD 103 103.7 UtcTWDD 103.7 108.9 UtcTWDD 108.9 109.3 MscRequired result:eg. Newly inserted data:HoleId mFrom mTo CodeTWDD 103 103.7 UtcTWDD 103.7 104 Utc <--new insertion TWDD 104 105 Utc <--new insertion TWDD 105 106 Utc <--new insertionTWDD 106 107 Utc <--new insertionTWDD 107 108 Utc <--new insertionTWDD 108 108.9 Utc <--new insertionTWDD 108.9 109 MSc <--new insertionTWDD 109 109.3 Msc <--new insertionMany TIA |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-08 : 14:24:32
|
| [code]SELECT t.HoleID,CASE WHEN FLOOR(mFrom)+v.number > mFrom THEN FLOOR(mFrom)+v.number ELSE t.mFrom END,CASE WHEN FLOOR(mFrom)+v.number > mTo THEN mTo ELSE FLOOR(mFrom)+v.number+1 END,t.CodeFROM YourTable tCROSS JOIN master..spt_values vWHERE v.type='p'AND FLOOR(mFrom)+v.number<CIELING(mTo)[/code] |
 |
|
|
|
|
|