question

DonD avatar image
DonD asked

How do I copy and truncate date to another column?

I need to copy the data from one column in a table to another column in the same table. The table I am copying to has a character limit of 10 and some of the data in the table I am copying from has more than 10 characters. I want to copy the data and truncate it so it does not exceed the 10 character limit. How can I do this?
truncate
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mjharper avatar image
mjharper answered
hi - this should do it I think: UPDATE dbo.TableName SET NewColumn = LEFT(OldColumn,10)
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

DonD avatar image DonD commented ·
That did the trick, thanks
0 Likes 0 ·
JohnM avatar image JohnM commented ·
Please make sure to accept the answer for your question. This will help to let people know that you got an answer as well as help others in the future. Thanks!
0 Likes 0 ·
JohnM avatar image
JohnM answered
I think that @mjharper has the correct answer, however I would ask why would you want to truncate the data? Won't you be missing some potentially viable data? I don't know your environment or specifics, but can you not expand the target column to match the size of the source column? NOTE: There can be gotchas with doing this so testing would be crucial. Just a thought.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

DonD avatar image DonD commented ·
Yes, mj harpers soluiton does work. John Moorehouse, the data is not pimary data but more of an alias to the data I am copying. The data is relevant to the user name and the table I am copying to is relevant to initials. The column I am copying form is unique and the column I am copying to needs t be unique intials. this will keep the user identifiable and unique
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.