Convert function and omitting the optional length parameter

  • I'm keen to use the convert function to convert many (100s) of nvarchar columns to varchar columns via creation of a view and an SSIS package.

    Each column has different length or many of them do.

    If I use convert function and do not specify a length, will the convert function keep the column size of the source for the function result ?

    I guess try and find out ! ..

    Seems to come up with all the columns as varchar(30) ...
    Seems I will have to put in the effort and specify the length wanted for the output columns of the view in each convert function.

  • If you do not specify a length, SQL will use the default size for that data type.  in the case of char and varchar, the default is 30.

  • DesNorton - Monday, March 18, 2019 2:38 AM

    If you do not specify a length, SQL will use the default size for that data type.  in the case of char and varchar, the default is 30.

    Yeah... one more think that MS did wrong - defaults like this break things in the long run - not mentioning a size should give an error and force the developer to state the correct size.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply