Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop View with a parameter

Status
Not open for further replies.

phildude

IS-IT--Management
Apr 16, 2001
12
0
0
US
I thought this would be a piece of cake, but it hasn't gone as smoothly as I expected. I need to drop a bunch of views, but I don't want to hardcode the drop command since the names change. When I try to do a drop view @viewname it gives me a syntax error - am I missing something?
Phil
 
Yes, you missed the point that SQL doesn't allow the use of variables to name objects in SQL commands. You must use dynamic SQL to accomplish this task.

Declare @sql varchar(60)
Select @sql='Drop View '+@viewname
Exec(@sql) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top