Prev: SQL 2008 passing Table-Value-parameters to stored proc via ODBC
Next: Insert multiple rows with stored procedures
From: Erland Sommarskog on 20 Dec 2009 06:31 led (l.r.m.d(a)sapo.pt) writes: > i have availibility calendar that have rows with > startdate and end date: > > select startdate,enddate where cod_casa="record from the first select" > and livre=0 > > it is possible to loop between startdate to enddate? Well, you don't really loop in SQL. But say that you have an orders table, and you want show the numbers of orders as defined by a calender table. That is, you only want to show data for the days in that table. Then you would do: SELECT C.OrderDate, COUNT(O.OrderDate) FROM Calender C LEFT JOIN Order O ON C.Date = O.OrderDate GROUP BY C.OrderDate I can't give an example for you procedure, because I don't really see how your available calender fits into your query, but hopefully this helps you to get going. -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: --CELKO-- on 21 Dec 2009 19:59 SQL has no loops. SQL has no sequential data access. It is a declarative language that works with completed sets of rows, not records from sequential files. If you don't know anything about RDBMS, then get a copy of the simplest intro book I know -- http://www.amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905
From: TheSQLGuru on 21 Dec 2009 23:18 Actually you are incorrect. TSQL provides several ways to do loops and sequential data access. -- Kevin G. Boles Indicium Resources, Inc. SQL Server MVP kgboles a earthlink dt net "--CELKO--" <jcelko212(a)earthlink.net> wrote in message news:50257da0-f13d-4bca-8914-cad160110471(a)v30g2000yqm.googlegroups.com... > SQL has no loops. SQL has no sequential data access. It is a > declarative language that works with completed sets of rows, not > records from sequential files. > > If you don't know anything about RDBMS, then get a copy of the > simplest intro book I know -- > http://www.amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905 > > >
From: Tony Rogerson on 22 Dec 2009 03:20 --CLEKO-- You appear to be posting on the wrong forum. SQL Server does have loops, it does have sequential access, it has xml, it has unstructured search, it has mdx, it has dmx, it has .... well, a ton of other stuff. If you don't know anything about SQL Server (remember - this forum is for users of SQL Server) then check out books online which can be easily found on the internet. --ROGGIE-- "--CELKO--" <jcelko212(a)earthlink.net> wrote in message news:50257da0-f13d-4bca-8914-cad160110471(a)v30g2000yqm.googlegroups.com... > SQL has no loops. SQL has no sequential data access. It is a > declarative language that works with completed sets of rows, not > records from sequential files. > > If you don't know anything about RDBMS, then get a copy of the > simplest intro book I know -- > http://www.amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905 > > >
From: Erland Sommarskog on 22 Dec 2009 18:12 --CELKO-- (jcelko212(a)earthlink.net) writes: > SQL has no loops. SQL has no sequential data access. It is a > declarative language that works with completed sets of rows, not > records from sequential files. The other day you said: > There is a WHILE loop in T-SQL last time I looked. Does the T-SQL > compiler remove invariant expressions in the WHILE loop? Does the T-SQL > compiler unroll a WHILE loop (granted that is easier with a counting > loop)? While there are no loops in SQL, you still care about whether SQL Server unrolls them! -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
|
Next
|
Last
Pages: 1 2 3 Prev: SQL 2008 passing Table-Value-parameters to stored proc via ODBC Next: Insert multiple rows with stored procedures |