I'm trying to remove the first character in LastNames that start with a space. The code below seems to clear LastName entirely, making the field empty. Do you see something wrong?
DECLARE @Id int
DECLARE @LastName NVARCHAR(255)
while (SELECT COUNT(*) FROM [Table] WHERE LastName LIKE ' %') > 0
Begin
Select Top 1 @Id = Id, @LastName = LastName FROM [Table] WHERE LastName LIKE ' %'
UPDATE [Table] SET LastName = SUBSTRING(@LastName, 1, LEN(@LastName)) WHERE Id = @Id
End