Reputation: 2186
SELECT
INT_VALUE = NULL -- Result Data Type = INT
,STR_VALUE = NULL -- Result Data Type = INT
I want to make sure that STR_VALUE is a varchar NULL and not int NULL. I need this to be done in SELECT statement and in derived column.
How can I achieve that?
Thank you
UPDATE: Thanks guys for really quick feedback. just "fyi" kind of thing, I am trying to create a lookup query for an ETL app and wanted to see if I could create NULL string column in t-sql rather than creating an ETL app based NULL string derived column.
Thx
Upvotes: 1
Views: 441
Reputation: 39777
If you're creating a table based on your SELECT (e.g. SELECT INTO) you can also use cast/convert:
SELECT NULL as INT_VALUE, CAST(NULL as Varchar(10)) AS STR_VALUE
INTO MyNewTable
Upvotes: 1
Reputation: 1269753
NULL
defaults to an int. You can change it to any other type using cast()
:
SELECT INT_VALUE = NULL, -- Result Data Type = INT
STR_VALUE = cast(NULL as varchar(255)) -- Result Data Type = varchar(255)
Upvotes: 3
Reputation: 152556
Just CAST
it:
SELECT
INT_VALUE = CAST(NULL AS int)
,STR_VALUE = CAST(NULL as VARCHAR(10))
Upvotes: 1