There are more effects for economy then just what you mentioned.
For example, if a car factory is built in a certain state, does it improve the economy solely by creating jobs and generating car sales thereby increasing the regional GDP?
Not only because of this there are also other effects. Depending on what kind of investment it is it can support technology transfer between the countries or also increase stock of human capital (through on job training/learning by doing), which according to endogenous growth theories can accelerate economic growth itself (although it is worth noting endogenous growth theory is still not completely accepted by profession even though Romer who developed it even received Nobel Prize for it because it’s hard to test).
Moreover, apart from such dynamic growth effects there are more beneficial macroeconomic effects on GDP. From macroeconomic perspective all spending including investment has a multiplier attached to it. For when the factory increases GDP by the investment people will also have more money to spend increasing GDP even further and so on. From macroeconomic perspective your spending/investment is someone’s else income so if you increase your spending/investment other people will spend more as well.
Also aside from macroeconomic effects any new job openings put upward pressure on wages, however depending on how many jobs are offered and what is already situation in the market this effect might be very small.
if a factory (lets say it’s located in state A) ONLY ships and sells its products to state B, would it improve state A’s economy as much as if sales were only made in state A?
Not really as measured by GDP. The GDP identity is given by:
Where C is consumption I investment G gov. spending, X export and M import.
So even just looking at the identity it is possible to see that if the cars are not consumed but exported GDP does not change.
However, there is even more to it. Trade theory in economics tells us that there are both static and dynamic gains from trade. Hence to the extent that the cars are exported because in state A they can be produced more efficiently then in state B, and in exchange state B trades to state A some of its products that they can produce more efficiently there will be both static one time increase in the level of their welfare from specialization, and also potentially some dynamic effect assuming that the longer the state specialize in the good they have comparative advantage in the better they become at its production.