Changing Column length dynamically

Padmanabhan, Venkatesh 246 Reputation points
2021-01-12T08:50:21.56+00:00

HI.
I have a table which contains few columns which are of fixed length. The source from which I receive the data - the data is getting changed every time with differing length for the columns.
This results in SSIS jobs to fail. Is it possible to increase the column length dynamically depending on the data being received ? what are the other ways to resolve this, if the dynamic column is not a possibility?
Thanks

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
SQL Server Other
{count} votes

4 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2021-01-12T09:17:35.957+00:00

    Is the column data type CHAR = fixed length string? Then use VAR CHAR ( var = variable length) with a appropriate length instead.


  2. tibor_karaszi@hotmail.com 4,316 Reputation points
    2021-01-12T10:53:07.417+00:00

    You first said that the length is fixed and then said it is varchar (which is variable). Which is it? Char or varchar?

    Anyhow, assuming it is varchar, and not char. I.e., it isn't fixed it is variable with a max length of 100. What you need to do is to specify a max length that satisfies your needs. That is what varchar is for! If you need max 1000, then specify marchar(1000). Etc. It is as simple as that!

    0 comments No comments

  3. Tom Phillips 17,771 Reputation points
    2021-01-12T15:20:28.977+00:00

    SSIS requires known field names and sizes at design time. Those values cannot be changed during runtime.

    You would need to allow for the max values to do what you are trying to do in SSIS.

    0 comments No comments

  4. Monalv-MSFT 5,926 Reputation points
    2021-01-13T06:14:07.23+00:00

    Hi @Padmanabhan, Venkatesh ,

    It is the Varchar column of 100 length.
    The data which the column is receiving is changing . sometimes the column gets data with 50 characters, sometimes 500 , sometimes 1000. The data varies

    We can use the following sql query in SSIS Execute SQL Task to change the datatype of column from varchar(100) to varchar(8000) or varchar(max).

    ALTER TABLE YourTableName ALTER COLUMN YourColumnName Varchar(8000);
    GO

    Please refer to char and varchar (Transact-SQL) and changing the size of a column.

    Best Regards,
    Mona

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.