sale of second home

I live in state A and sold a second home in state B, a non-rental.  do i complete federal 1040,  and state 1040 in  state  A , and then state B 1040?  and in what order?  Does it make adifference?