3

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Baub
  • 723
  • 4
  • 21
  • 36

2 Answers2

11

Try replacing the null with

CAST(null as VARCHAR)
Jonny
  • 2,509
  • 23
  • 42
  • 4
    Make sure that also specify the SIZE of the field. `CAST(NULL as VarChar(20))` replacing 20 with the appropriate size. – Declan_K Aug 15 '13 at 15:44
2
SELECT field1, field2, convert(varchar, NULL) as MyField
INTO NewTable
FROM OldTable
Luis LL
  • 2,912
  • 2
  • 19
  • 21