You are here: Re: Update n rows « MsSQL Server « IT news, forums, messages
Re: Update n rows

Posted by Erland Sommarskog on 03/25/06 12:05

Khan (amir@programmer.net) writes:
> I'm using where condition e.g. " where assign = ' ' ". but this
> condition is true for 100 rows, and i want to update only first 15
> rows, otherwise all 100 rows will be updated which i don't want.
> I tried SET ROWCOUNT but coud'nt get through.

Try:

SET ROWCOUNT @n
INSERT #temp (...)
SELECT ... FROM tbl WHERE assign = ' '

SET ROWCOUNT 0

UPDATE tbl
SET assign = 'X'
FROM tbl
JOIN #temp ON tbl.keycol = #temp.keycol

This presumes that the rows has a key that you can identify them with.

I also repeat the suggestion from my previous post, include:

o CREATE TABLE statement for your table.
o INSERT statements with sample data.
o The desired result given the sample.

This increases your chances to get a useful response.

By the way, which version of SQL Server are you using?

--
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

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