What's a good no-op in T-SQL? I want to use it as a place-holder in boilerplate code snippets. For example, if I'm stubbing out a query/UDF and have something like this:
IF @parm = 1
BEGIN
END
IF @parm = 2
BEGIN
END
I'll get the following error:
Incorrect syntax near the word 'END'
What could I throw in between there that would silence the compiler i.e. be executable?
The go to solution for removing duplicate rows from your result sets is to include the distinct keyword in your select statement. It tells the query engine to remove duplicates to produce a result set in which every row is unique.
SQL Min, Max. SELECT DISTINCT returns only unique values (without duplicates). DISTINCT operates on a single column. DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc.
An alternative for IN and EXISTS is an INNER JOIN, while a LEFT OUTER JOIN with a WHERE clause checking for NULL values can be used as an alternative for NOT IN and NOT EXISTS.
As mentioned here you could declare a dummy variable. It shouldn't appear anywhere at all (execution plans, printed output etc):
IF @parm = 1
BEGIN
DECLARE @dummy1 bit
END
IF @parm = 2
BEGIN
DECLARE @dummy2 bit
END
Alternatively, you can use a label too:
IF @parm = 1
BEGIN
noop1:
END
IF @parm = 2
BEGIN
noop2:
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With