Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a NULL column when SELECT'ing INTO a new table?

I have a statement like this:

SELECT field1, field2, MyField = NULL
INTO NewTable
FROM OldTable

This does what I want with one exception: the field I created MyField and filled with NULL is an INT type and I'd like it to be a VARCHAR type. I don't know how to modify the same statement to create the new field with the VARCHAR type.

Thanks.

like image 691
Baub Avatar asked Oct 26 '25 10:10

Baub


1 Answers

Try replacing the null with

CAST(null as VARCHAR)
like image 131
Jonny Avatar answered Oct 28 '25 22:10

Jonny