Currently I put my query in a variable like this.
query = @" select top 1
u.UserID
from
dbo.Users u
where
u.SystemUser = 1
and u.Status = @Status";
The problem with this is that indentation is lost when going to a new line and I have to add it myself.
Does anyone know of a better way? I know stored procedures are a possibility (eliminating this indentation problem), but I’m not sure if they are necessarily better for pure data retrieval.
Ignore the TSQL haters; there’s nothing inherently wrong with knowing some TSQL! Anyway, I would approach this by (if I keep your formatting, which isn’t my norm – but… meh);
By keeping your TSQL over to the left, any indentation etc is easier to do in the IDE, but it also makes your TSQL shorter, and is easier to debug when looking at a trace, as it isn’t bizarrely 30-something characters in. Starting with a newline before the
selectalso helps keep things tidy.Personally, I also find the disjoint between the code indent and the TSQL indent helps find TSQL – and TSQL is pretty important to me, so this is a good thing. And emphasising that we’ve just switched “world” (for want of a better term) is not harmful, either.