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.
| Author |
Topic |
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2010-05-26 : 12:15:21
|
| Im trying to check if a view exists and if it does alter itim using:IF OBJECT_ID('view1', 'V') IS NOT NULLBEGINALTER VIEW view1ASselect top 10 *from tabletestENDim getting Incorrect syntax near the keyword 'VIEW'.the error seems to be with the begin/end. what am i doing wrong? |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-05-26 : 12:37:17
|
You can't put anything before the ALTER statement. You could try drop and recreate the viewIF OBJECT_ID('view1', 'V') IS NOT NULLDROP VIEW view1GOCREATE VIEW view1ASselect top 10 *from tabletestJimEveryday I learn something that somebody else already knew |
 |
|
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2010-05-26 : 12:43:50
|
| ok thanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-05-27 : 03:08:37
|
| or use dynamic sqlIF OBJECT_ID('view1', 'V') IS NOT NULLEXEC('ALTER VIEW view1ASselect top 10 *from tabletest')MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|