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
 Update the first row with field value = 0

Author  Topic 

silviorp
Starting Member

2 Posts

Posted - 2011-09-15 : 12:12:58
Hi guys.
I have a table with the following structure:

OBJ_GROUP_ID -- BACKUP_STATUS_ID -- DESCRIPTION
0 || 1 || No restriction
1 || 0 || null

I need a query that scan my table, find the first row that the BACKUP_STATUS_ID is 0 and update that row. How should I do that?

The rest of this job depends on this information!

Thanks in advance!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-09-15 : 12:40:32
UPDATE yourTable
SET yourColumn = somevalue
WHERE obj_group id = (select min(obj_group_id) from yourTable where BACKUP_STATUS_ID = 0)

Jim

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-15 : 12:41:42
is OBJ_GROUP_ID unique valued column?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

silviorp
Starting Member

2 Posts

Posted - 2011-09-15 : 13:10:03
jimf, your code works when updating the backup_status_id. I just have to update the backup_status_id and the description.

I`m new to sql and that`s not what I was supposed to work with but I`m trying.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-15 : 13:23:17
[code]UPDATE yourTable
SET BACKUP_STATUS_ID = somevalue,
DESCRIPTION=someothervalue
WHERE obj_group id = (select min(obj_group_id) from yourTable where BACKUP_STATUS_ID = 0)[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -