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
 Very simple DELETE question

Author  Topic 

muppit
Starting Member

4 Posts

Posted - 2006-10-25 : 17:02:19
Hi all,

I have been asked to delete a selection of records from a SQL database. I have created a view which SELECTS the records I need to delete. But I have no idea how to convert to DELETE them!

The SQL statement currently is:

SELECT     dbo.TransPerPaySequence.*, PaySequence AS PaySeq
FROM dbo.TransPerPaySequence
WHERE (PaySequence IN (138, 125, 115, 110, 98, 90, 84, 76, 69, 63, 54, 46, 36, 25))


Can someone please help with the correct code to convert this to a DELETE action.

Many thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-25 : 17:06:38
DELETE
FROM dbo.TransPerPaySequence
WHERE (PaySequence IN (138, 125, 115, 110, 98, 90, 84, 76, 69, 63, 54, 46, 36, 25))

Tara Kizer
Go to Top of Page

muppit
Starting Member

4 Posts

Posted - 2006-10-25 : 17:13:06
Hi,

Thanks for that. I have tried that before and get an error message telling me "The SQL statement type cannot be used in a view. Only a SELECT statement may be used."

I am using Enterprise Manager to perform this action - does that make a difference?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-25 : 17:16:41
Well you can't put the delete statement in a view. You didn't post the view, so I wasn't sure what you had.

Just delete from the view:

DELETE FROM ViewName

Why do you need a view?

Tara Kizer
Go to Top of Page

muppit
Starting Member

4 Posts

Posted - 2006-10-25 : 17:20:29
I probably don't need a view! I firstly created the view to make sure I was trapping the correct records to delete...

Can you advise how I should be doing this delete action from the table then? Willing student! :0)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-25 : 17:21:19
quote:
Originally posted by muppit

I probably don't need a view!

Can you advise how I should be doing this delete action from the table then? Willing student! :0)



Just use the query in my first post.

Tara Kizer
Go to Top of Page

muppit
Starting Member

4 Posts

Posted - 2006-10-25 : 17:24:09
Bingo!

Thank you! I really must get my books out and dust them off - it's been a long time since I did the training course.

Thanks for your help. All good now.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-26 : 09:44:11
Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

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

- Advertisement -