I own both lenses. IMHO, each is excellent in its own right, but for different reasons.
Starting with the Sigma 17-50 f/2.8, it has a versatile focal length range and is very usable at f/2.8. But it's quite big and heavy for an APS-C lens. AF performance - at least on my copy, when paired with my K-3 / K-3II and earlier cameras - is best described as "reasonably good". I'm in the habit of auto-focusing once, then a second time, to make sure it's absolutely spot on. That's not a problem for me, but I'm aware of having to do it, and it's not ideal if you're shooting moving subjects at wider apertures. The near-silent DC AF motor is a welcome bonus, though. And I really like how sharp and detailed this lens is from edge-to-edge. Really quite impressive, especially for a zoom. And yet... I find the rendering to be somewhat "clinical", by which I mean, my perception is that it doesn't lend much of its own character to photos. I don't feel any "magic" coming from the lens. That's not a criticism of it, but merely a personal observation. I haven't had any real problems with flare control, though I do notice some lateral chromatic aberration at wider focal lengths. But it's correctable in post-processing.
And now the DA21. I have the HD rather than the SMC version, but in most respects my views should be relevant to both. The HD DA21 is one of my favourite Pentax lenses (and undoubtedly my favourite DA Limited). It may not be as edge-to-edge sharp as the Sigma at wider apertures, but the rendering has so much more character to my eye. It adds something over and above my own composition and choice of lighting that the Sigma doesn't. Plus it's compact, light, all metal in construction, and the AF is always spot-on first time, even if the screw-drive is a bit noisy.
I think it's really difficult for to choose between the two. It really depends on your use cases. At 21mm, for me, the DA21 runs rings around the Sigma 17-50 f/2.8 because of its rendering. It has character, and that counts for a lot in my book. But the Sigma, whilst less characterful and much bigger / heavier, offers an awful lot of versatility. Only you can decide which is more applicable to your needs
I wouldn't want to choose... I'd rather keep both, for different applications. If I was forced to pick one, though, I'd grudgingly go with the Sigma 17-50 f/2.8 for versatility alone. But my heart would forever wish that I'd kept the DA21 for those situations where it's applicable