Click here to Skip to main content
15,888,293 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRecursion in SQL Pin
dan!sh 14-May-18 1:50
professional dan!sh 14-May-18 1:50 
GeneralRe: Recursion in SQL Pin
Jörgen Andersson14-May-18 3:27
professionalJörgen Andersson14-May-18 3:27 
GeneralRe: Recursion in SQL Pin
Richard Deeming14-May-18 8:50
mveRichard Deeming14-May-18 8:50 
GeneralRe: Recursion in SQL Pin
Super Lloyd14-May-18 16:52
Super Lloyd14-May-18 16:52 
GeneralRe: Recursion in SQL Pin
dan!sh 14-May-18 19:36
professional dan!sh 14-May-18 19:36 
GeneralRe: Recursion in SQL Pin
Super Lloyd14-May-18 21:18
Super Lloyd14-May-18 21:18 
GeneralRe: Recursion in SQL Pin
GuyThiebaut14-May-18 20:45
professionalGuyThiebaut14-May-18 20:45 
GeneralRe: Recursion in SQL Pin
DaveAuld19-May-18 21:36
professionalDaveAuld19-May-18 21:36 
I resorted to a GOTO in an SQL query Loop that created a new transaction to work round a repetitive action with an unknown data set size. It was dirty, but worked. Glad I didn't try recursion as that would have definitely ended in tears by the sound of things!

You can read about the problem here.....Developing Automated Data Purge Solution, but it basically looks like this;
SQL
LoopStart:
IF (@Count - @RowCountTotal) > @BatchSize 
 Begin
  Begin Transaction
   Delete Top (@BatchSize) From Comment Where CommentTime < @StartDate
   Set @RowCountTotal = @RowCountTotal + @@RowCount
  Commit Transaction
  Goto LoopStart
    End
Else
 If (@Count - @RowCountTotal) > 0
  Begin<br />
   Begin Transaction
    Delete Top (@Count - @RowCountTotal) From Comment Where CommentTime < @StartDate
    Set @RowCountTotal = @RowCountTotal + @@RowCount<br />
   Commit Transaction
  End
Dave
Find Me On:Web|Youtube|Facebook|Twitter|LinkedIn
Folding Stats: Team CodeProject

GeneralRe: Recursion in SQL Pin
David A. Gray25-Jun-18 11:26
David A. Gray25-Jun-18 11:26 
GeneralTime Stamps Rendered by CMD.exe Pin
David A. Gray13-May-18 19:43
David A. Gray13-May-18 19:43 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
Jochen Arndt13-May-18 20:56
professionalJochen Arndt13-May-18 20:56 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
David A. Gray14-May-18 10:17
David A. Gray14-May-18 10:17 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
Jochen Arndt14-May-18 12:12
professionalJochen Arndt14-May-18 12:12 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
David A. Gray16-May-18 6:58
David A. Gray16-May-18 6:58 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
Randor 14-May-18 16:58
professional Randor 14-May-18 16:58 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
David A. Gray16-May-18 6:30
David A. Gray16-May-18 6:30 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
Randor 16-May-18 16:01
professional Randor 16-May-18 16:01 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
David A. Gray17-May-18 4:44
David A. Gray17-May-18 4:44 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
Randor 17-May-18 10:01
professional Randor 17-May-18 10:01 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
DaveAuld19-May-18 21:37
professionalDaveAuld19-May-18 21:37 
GeneralRe: Time Stamps Rendered by CMD.exe Pin
David A. Gray21-May-18 7:15
David A. Gray21-May-18 7:15 
GeneralSunday morning, and Microsoft has rebooted my laptop... Pin
charlieg13-May-18 2:46
charlieg13-May-18 2:46 
GeneralRe: Sunday morning, and Microsoft has rebooted my laptop... Pin
Slacker00713-May-18 3:11
professionalSlacker00713-May-18 3:11 
GeneralRe: Sunday morning, and Microsoft has rebooted my laptop... Pin
raddevus13-May-18 3:31
mvaraddevus13-May-18 3:31 
GeneralRe: Sunday morning, and Microsoft has rebooted my laptop... Pin
charlieg13-May-18 3:58
charlieg13-May-18 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.