Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can i use for a no-op in T-SQL? [duplicate]

Tags:

syntax

sql

tsql

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?

like image 985
kmote Avatar asked Jun 29 '12 21:06

kmote


People also ask

How do I get no duplicates in SQL query?

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.

What is the term used to select non duplicates in SQL?

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.

What can be used instead of not in in SQL?

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.


1 Answers

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
like image 79
Jon Egerton Avatar answered Oct 14 '22 11:10

Jon Egerton