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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 VIEW with non existing additional columns

Author  Topic 

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 2009-04-17 : 14:39:11
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

52326 Posts

Posted - 2009-04-17 : 14:41:29
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 - 2009-04-20 : 14:31:03
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 - 2009-04-20 : 14:33:45
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 - 2009-04-20 : 15:08:04
I found it by using CAST
Go to Top of Page

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2009-04-20 : 15:09:15
Try:
CREATE VIEW TestView
AS
SELECT Field1,Field2, CAST(NULL as NVARCHAR(512)) AS NonExistentField
FROM YourTable
Go to Top of Page
   

- Advertisement -