Get current site URL


Please login or register to vote for this query.

(click on this box to dismiss)

Get the URL of SE site the query is run against. Please note: if you need to link a page from the currently selected site use the 'site://' protocol instead (check the following:

IT Security

Q&A for IT security professionals

DECLARE @site VARCHAR (500), @name VARCHAR(500)
DECLARE @idx_exported INT, @idx_meta INT, @idx_se INT
SET @name = db_name()
SET @site = 'stackoverflow'
SET @idx_exported = PATINDEX('%.Exported', @name)
SET @idx_meta = PATINDEX('%.Meta.%', @name)
SET @idx_se = PATINDEX('StackExchange.%', @name)
IF @idx_se = 1 
 IF @idx_meta = 0 SET @site=SUBSTRING(@name, 15, @idx_exported - 15) + '.stackexchange'
 ELSE SET @site='meta.' + SUBSTRING(@name, 15, @idx_meta - 15) + '.stackexchange'
 IF @idx_meta = 0 SET @site=SUBSTRING(@name, 1, @idx_exported - 1)
 ELSE SET @site='meta.' + SUBSTRING(@name, 1, @idx_meta - 1)

SET @site = 'http://' + LOWER(@site) + '.com/'

SELECT @site

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results