I've made myself a little query on the stack exchange data explorer which gets a leader board for the top comments on the site, and the URL for the post that the comment was posted on.

This query could theoretically run on any of the sites without a problem - the only difference is the site's URL.

To generate the URL of the post, I use the following code as part of the SELECT statement.

'http://stackoverflow.com/' + 
LEFT(pt.Name,1) + '/' + cast(c.postId as varchar) as [URL]

Now the only part of my query which won't work cross-site is the initial part of the URL, in this case http://stackoverflow.com/ - is it possible to parameterise the URL of the site that the query was executed against in the Stack Exchange Data Explorer?

This would allow for such use of URLs inside the query whilst enabling the query to be run against different sites.

2 Answers 2


In this particular case it's probably easiest to just change your selection to use the magic Post Link column with c.PostId AS [Post Link], which will automatically generate a link to the post in question in the results table, as seen here.

Update: For your particular use case, I went ahead and added support for [Comment Link] (pending waffles' approval) since linking directly to comments is now officially supported in a way that makes this possible.

This is also now supported more generically: Provide convenient way to get the current site URL in SEDE query

  • wow thanks - never knew about that - how can you find out about things like that with the data explorer? Dec 23, 2011 at 14:38
  • 2
    There's some information in the FAQ (see "What's the deal with magic columns?" in particular), but there's a desire to make these features a little more obvious in the future.
    – Tim Stone
    Dec 23, 2011 at 14:40

If you just wish to get the current site URL (e.g.: http://stackoverflow.com/ or http://meta.apple.stackexchange.com/) you may use the following query:

   Get current site URL

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .