Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Single update statement..

Author  Topic 

MageshkumarM
Yak Posting Veteran

61 Posts

Posted - 2011-03-15 : 09:31:16
Hi,

I need a small statement to UPDATE first 3 rows.. without where case.
I have table A in that i had 300 rows.. i want to update first 3 rows..


can any one help me out of this..

Thnk in advance





MAG,
Start with the new Idea..
http://mageshkumarm.blogspot.com/

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-15 : 09:58:59
Why don't you want to use WHERE or CASE? If you don't want to use the tools SQL provides you, the best way is to jsut open the table in SSMS and manually update the first 3 rows you see.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-15 : 10:12:04
quote:
Originally posted by MageshkumarM

Hi,

I need a small statement to UPDATE first 3 rows.. without where case.
I have table A in that i had 300 rows.. i want to update first 3 rows..


can any one help me out of this..

Thnk in advance





MAG,
Start with the new Idea..
http://mageshkumarm.blogspot.com/


Why do you want not to use where clause?


update top (3) from table set col='somevalue'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sqldataguy
Starting Member

12 Posts

Posted - 2011-03-15 : 11:00:01
I also wonder why you don't want to use WHERE or CASE, but taking your word for it.... Copy the primary key of the rows you want to update to a temp table, then inner join the initial table with the temp table in the UPDATE statement so it will only update those three rows
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-03-15 : 23:29:05
quote:
Originally posted by MageshkumarM


I need a small statement to UPDATE first 3 rows.. without where case.
I have table A in that I had 300 rows.. I want to update first 3 rows..



Tables have no ordering by definition so this makes no sense. Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help.


--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -