I have a table, that has many columns with all kinds of datatypes. I want to fill these columns with values that will be of same length as the size of the field.
For example, if a table has a column called:
Test Varchar(255) NULL
Now this column can have values ‘yes’ or ‘no’. But I want to fill this column to its max capacity, that is all 255 charachters. The value could be any random data. And I want to do this for all the columns in the table. Assume that all fields are varchar.
If you declare the column using
CHARinstead ofVARCHAR, SQL Server will always pad the field to the full width.Alternatively you could use
LENandREPLICATEto pad the field manually with spaces (either left or right)Another common trick is to pad with too many spaces and then truncate e.g.
Take your pick.