You are here: Re: Creating rows based on date range from another table « MsSQL Server « IT news, forums, messages
Re: Creating rows based on date range from another table

Posted by Erland Sommarskog on 08/22/06 08:12

Ed Murphy (emurphy42@socal.rr.com) writes:
> I disagree, but then I have somewhat more experience with imperative
> than functional programming. Consider:
>
> x = first_date
> while x <= last_date
> insert x, datediff(x, mid_date) into <table>
> x = dateadd(x, 1)
> end while
>
> versus
>
> select dateadd(first_date, n), n - datediff(mid_date, first_date)
> into <table>
> from numbers
> where n between 0 and datediff(end_date, first_date)
>
> Okay, "where n between <limits>" makes sense as an analogue to a while
> loop, but that stuff in line 1 looks like the stuff of headaches.

Loops are particularly prone to two sorts of errors:

* They goes on forever, could be because of a sloppy mistake, of because the
logic is complicated.
* One-off errors because of incorrect loop conditions.

One-off errors are easy to make with set-based queries as well, but the
risk of infinite loops is nothing you have to lose sleep over.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация