That's what I did when I went around northern Europe.
Took the Stockholm to Malmo, and then switch to Copenhagen.
Unfortunately, I don't think there was sleeper cars.
That train departed late evening, got us there in the daytime. I figured if I'm paying to sleep, I might as well be moving. I only wish that there was bunks on that train.