SwolleyBible
SwolleyBible

Reputation: 273

Creating a view with constant text column

Easy question I can't seem to find an easy answer to. Why, in MSSQL, can't I create a " " and a "CONSTANT_TEXT_VALUE" column in the view below? There should be a way of doing this right?

CREATE VIEW TEST_VIEW AS
SELECT DEPT,
SALES,
"" AS BLANK_COLUMN,
"Some Text" AS CONSTANT_TEXT_VALUE
FROM SOME_TABLE

Upvotes: 0

Views: 5157

Answers (2)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

Use single quotes.

CREATE VIEW TEST_VIEW AS
SELECT DEPT,
SALES,
' ' AS BLANK_COLUMN,
'Some Text' AS CONSTANT_TEXT_VALUE
FROM SOME_TABLE

Upvotes: 5

Gordon Linoff
Gordon Linoff

Reputation: 1269973

The text delimiter in SQL Server follows the ANSI standard. It is a single quote:

CREATE VIEW TEST_VIEW AS
    SELECT DEPT, SALES,
           '' AS BLANK_COLUMN, 'Some Text' AS CONSTANT_TEXT_VALUE
    FROM SOME_TABLE;

Upvotes: 6

Related Questions