Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

here is my query:

CREATE VIEW VIEW2
AS SELECT [Column1],
(NULL) AS column2 VARCHAR(10)
FROM VIEW1;

I get an error in the third line.

If I leave the query like this, without specifying the data type for Column2, the query works, but the default data type will be int, whereas I want to have VARCHAR.

CREATE VIEW VIEW2
AS SELECT [Column1],
(NULL) AS column2 
FROM VIEW1;

Can you please help? Thank you!

Note: Only Column1 is in VIEW1. Column2 is NOT in VIEW1, it's a generated column with NULL values.

share|improve this question
    
You do know that views calling views is generally a very poor techinique and can cause performance issues? You really don't want to go down that path because it's anightmare to fix later when you have a lot of records and the performance issues show up. And I am at a loss as to why you would want to do this. If the column isn't in a table and it can only be NULL, what good is it doing you? You can't update it with any other values –  HLGEM Mar 19 '12 at 14:13
add comment

1 Answer

You'll want this.

CREATE VIEW VIEW2
AS SELECT [Column1],
cast(NULL as varchar(10)) AS column2
FROM VIEW1;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.