Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 157 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

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.

'' + 
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 - 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.

share|improve this question
up vote 5 down vote accepted

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

share|improve this answer
wow thanks - never knew about that - how can you find out about things like that with the data explorer? – Alex Coplan Dec 23 '11 at 14:38
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 '11 at 14:40

If you just wish to get the current site URL (e.g.: or you may use the following query:

   Get current site URL

share|improve this answer

You must log in to answer this question.

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