Showing posts with label limiting. Show all posts
Showing posts with label limiting. Show all posts

Monday, March 19, 2012

Copying from one column to another

It's all in the same table
How do I copy something from one column to another, but limiting it to only the first "x" characters?

so if i wanted to copy just 'ABC' instead of 'ABCDEFG' how could i do that?

thanks in advanceSomething like:

DECLARE @.x int; SET @.x = 3
UPDATE <table>
SET COL2 = LEFT(COL1,@.x)
|||Thank you :}

Can I ask what LEFT means?|||LEFT Returns the part of a character string starting at a specified number of characters from the left. In this case the left 3 characters.

Have a look into SQL Server Books Online.|||ooh so you could even do right?
and what about center?

i'll do that. you have any good sites offhand? i have a few sites but none seem to be "that great"|||Regarding the center or any other portion of a string that doesn't start at the left end or right end you would use the SUBSTRING function. In terms of sites for Tranact SQL I don't knwo of to many and have found the SQL Server Books Online reference to be pretty complete.

Cheers