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
 Help with delete query

Author  Topic 

yumyum113
Starting Member

31 Posts

Posted - 2007-04-05 : 20:29:59
Hi,

Not sure if this is possible in a delete query that is why I'm posting out of curiosity.

I have a table with one column (int datatype)

WorkItem
1
1
2
1
3
1

----(6 rows)

Can I delete the first record whose workitemid is 1

So that after the delete the resulting dataset in

WorkItemID
1
2
1
3
1

----(5 rows)

Thanks,

yumyum113

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-05 : 21:57:35
[code]
set rowcount 1
delete table where workitemid = 1
set rowcount 0
[/code]


KH

Go to Top of Page

yumyum113
Starting Member

31 Posts

Posted - 2007-04-05 : 22:05:13
Thanks for the reply.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 23:33:42
Make sure that you reset rowcount to 0 at the end as Tan specified. Otherwise you will end up with unexpected results

Madhivanan

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

yumyum113
Starting Member

31 Posts

Posted - 2007-04-06 : 05:38:35
Thank you Guys for your help... I really must say this forum rocks!!!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-06 : 06:32:37
SQL Server 2005 can use the syntax

DELETE TOP 1
FROM Table1
WHERE ID = 1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-06 : 06:48:00
quote:
Originally posted by Peso

SQL Server 2005 can use the syntax

DELETE TOP 1
FROM Table1
WHERE ID = 1


Peter Larsson
Helsingborg, Sweden


Thats cool
Is Order by also possible?

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-06 : 08:24:43
No.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-06 : 11:13:04
Why are you giving solutions to a problem that makes no sense?

Are you trying to eliminate "duplicates"?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -