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
 ALTER VIEW and Add Column

Author  Topic 

forrestgump
Starting Member

19 Posts

Posted - 2013-02-05 : 06:21:47
Hi there,

I was wandering if there is a way of altering a view and adding a column. I have the following code and column which I wish to add.

CASE WHEN [UKUS] IS NOT NULL THEN [UKUS] ELSE [MoW] END AS OfferMade

I have tried the following code but to no avail.

ALTER VIEW Q1_GPO_Dataset
ADD OfferMade
CASE WHEN [UKUS] IS NOT NULL THEN [UKUS] ELSE [MoW] END AS OfferMade

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-02-05 : 06:55:18
ALTER VIEW is to use like CREATE VIEW. The difference is that the view does already exists. Read up in BOL.


Too old to Rock'n'Roll too young to die.
Go to Top of Page

forrestgump
Starting Member

19 Posts

Posted - 2013-02-05 : 07:37:35
I ended up just entering the view and then adding the code. Is this good practice? or should I really be using a different method?

Regards,

Forrest
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-05 : 07:43:24
Usually what I do is to right-click on the view name in SSMS object explorer, select Script View As -> Alter To -> New Query Editor Window. Once the window comes up, make the changes you want and execute.

By "entering the view" did you mean that you used the designer (right-click and then select the menu "Design")? If that is the case, that is just as good.
Go to Top of Page

forrestgump
Starting Member

19 Posts

Posted - 2013-02-05 : 07:49:04
Hi James K,

Yes I did reply using design. Thanks for your reply once again. And thak you webfred as well.

Regards,

Forrest
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-05 : 10:14:31
You are welcome Forrest - Glad to help.
Go to Top of Page
   

- Advertisement -