A meta post gives a nice snippet of SQL

declare @search nvarchar(max) = ##searchfor:string?carefully %listen##
select id [Post Link]
     , score
     , creationdate
     , lastactivitydate
     , closeddate 
     , owneruserid as [User Link]
from posts
where body like concat('%', @search, '%') collate SQL_Latin1_General_CP1_CI_AI
or title like concat('%', @search, '%') collate SQL_Latin1_General_CP1_CI_AI

What does double number sign ## mean in there?

I guess that is some kind of string syntax, but I cannot even guess a keyword for that. googling "number sign ## in SQL" returns "prefix temporary tables", which is not the case.


## surrounds a query parameter in the Stack Exchange Data Explorer (SEDE).

The portion after the ? is the displayed default parameter value.

From the SEDE Tutorial written by Monica Cellio:

Note: the particular syntax used for parameters is specific to SEDE. Everything we've said so far about SQL is true for all flavors of SQL; this is different.

As shown in this query, you refer to a parameter by surrounding its name with doubled pound signs, such as ##MinScore##. Optionally you can specify the data type (int (a whole number), float (a number with a decimal value, like 2.5), or string): ##MinScore:int##. If you specify a type then SEDE will validate values against that type, so that if you're expecting a number for score and somebody types "unicorn" the query won't run. If you don't specify a type, your query may receive unexpected inputs.

## has no meaning in standard SQL. Though not the case here, it is used in Transact-SQL as a prefix to identify a global temporary object:

Rules for regular identifiers

An identifier that starts with a number sign denotes a temporary table or procedure. An identifier that starts with double number signs (##) denotes a global temporary object. Although the number sign or double number sign characters can be used to begin the names of other types of objects, we do not recommend this practice.

  • It might be worth noting that you would use a global temporary table in SQL Server when you need to create a temporary table that must be accessed by multiple different sessions, but a permanent table is not ideal. – Paul Mar 6 '20 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.