That's a very broad question and there's not one answer to it. In general, if this is a joint pain (i.e. compression/hernia/etc in the spine) than I wouldn't recommend doing so without consulting an experienced teacher who can see the movement and suggest the appropriate modification OR even a completely different movement pattern. However, if this is a muscle pain, than as long as we're gentle, sun salutations can actually help. If you're not sure, I'd highly suggest to consult your yoga teacher :)
Should people with backpain do Surya namaskar?
That's a very broad question and there's not one answer to it. In general, if this is a joint pain (i.e. compression/hernia/etc in the spine) than I wouldn't recommend doing so without consulting an experienced teacher who can see the movement and suggest the appropriate modification OR even a completely different movement pattern. However, if this is a muscle pain, than as long as we're gentle, sun salutations can actually help. If you're not sure, I'd highly suggest to consult your yoga teacher :)