SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 ALTER VIEW and Add Column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

forrestgump
Starting Member

19 Posts

Posted - 02/05/2013 :  06:21:47  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 02/05/2013 :  06:55:18  Show Profile  Visit webfred's Homepage  Reply with Quote
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 - 02/05/2013 :  07:37:35  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 02/05/2013 :  07:43:24  Show Profile  Reply with Quote
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 - 02/05/2013 :  07:49:04  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 02/05/2013 :  10:14:31  Show Profile  Reply with Quote
You are welcome Forrest - Glad to help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000