Yes - that can be done.
However there may be problems because the SSD is set up for and expecting a laptop.
My suggestion would be to clone the desktop drive on to the SSD and then try the SSD.
Make the clone, shut down the computer, unplug, swap the drive cables (power, datat), and reboot.
Take your time and be careful not to undo any internal connection other than drives. You can even leave the existing drive in place until the drive swap succeeds.
If it does not work your original drive is still intact and you can learn from the experience and try again.
Cloning is very straightforward and there are free applications that will make a clone drive for you. E.g. Macrium Reflect. There are others.