These are the sentences:
ユニオンへサンドイッチを買いに行きました。
ユニオンへサンドイッチを買って行った。
Are they both grammatically correct? Also do they both mean the same thing, which by my translation is "I went to the union and bought a sandwich."
Do they only differ in their formality with the second sentence being more casual?