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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 VIEW with non existing additional columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 04/17/2009 :  14:39:11  Show Profile  Reply with Quote
Is it possible to create a view that select from a Table but adds column that are not existing in the table?

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/17/2009 :  14:41:29  Show Profile  Reply with Quote
yup. its possible . something like

CREATE VIEW TestView
AS
SELECT Field1,Field2,'your value' AS NonExistentField
FROM YourTable
....

Go to Top of Page

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 04/20/2009 :  14:31:03  Show Profile  Reply with Quote
how do you specified the Type of the nonexistingfield ? looks like it set it to int by default ..
Go to Top of Page

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 04/20/2009 :  14:33:45  Show Profile  Reply with Quote
hmm it's int because I did something like

CREATE VIEW TestView
AS
SELECT Field1,Field2, NULL AS NonExistentField
FROM YourTable


But I want it to be nvarchar(512)
Go to Top of Page

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 04/20/2009 :  15:08:04  Show Profile  Reply with Quote
I found it by using CAST
Go to Top of Page

jdaman
Constraint Violating Yak Guru

USA
354 Posts

Posted - 04/20/2009 :  15:09:15  Show Profile  Reply with Quote
Try:
CREATE VIEW TestView
AS
SELECT Field1,Field2, CAST(NULL as NVARCHAR(512)) AS NonExistentField
FROM YourTable
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