Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 17,545 of 19,505    |
|    Erland Sommarskog to Guy Dreger    |
|    Re: Insert Into with a row number.    |
|    10 Jul 09 21:37:15    |
      From: esquel@sommarskog.se              Guy Dreger (isgdre@HotMail.com) writes:       > Hi, I have a table that contains order information, each row contains       > information about a detail item that's been order but the key is OrderID       > and LineNumber.       >       > I'm trying to insert information into the table from another table but       > other table does not have any type of line number information. Also       > there is now hard value for the number of rows already in the order       > detail table.       >       > Is there a way to use “Insert into....” for this problem? I.e       >       > Insert into OrderDetails od (OrderID, Item, Description, LineNumber)       > select OrderID, '!NOTE!', Description, od.@ROWID() from OrderNotes              If you are on SQL 2005 or later (hint! it is always a good idea to       say which version of SQL Server you are using!), you can use the       row_number function:               row_number() OVER (PARTITION BY OrderID ORDER BY somecolumn)                            --       Erland Sommarskog, SQL Server MVP, esquel@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              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca