Q&A about the site for members of the workforce navigating the professional setting
DECLARE @SiteUrl VARCHAR(MAX) SET @SiteUrl = ( SELECT 'https://' + CASE WHEN DB_NAME() = 'StackOverflow' THEN 'stackoverflow' WHEN DB_NAME() = 'ServerFault' THEN 'serverfault' WHEN DB_NAME() = 'SuperUser' THEN 'superuser' WHEN DB_NAME() LIKE 'StackExchange.%%' THEN REPLACE(DB_NAME(), 'StackExchange.', '') ELSE 'stackexchange' -- Default or if it doesn't match anything specific END + '.stackexchange.com/q/' ) SELECT p.Id AS QuestionId, p.Title AS QuestionTitle, p.ViewCount AS ViewCount, CONCAT(LOWER(@SiteUrl), p.Id) AS QuestionURL FROM Posts p WHERE p.PostTypeId = 1 -- This denotes a Question AND p.OwnerUserId = ##UserId:int## ORDER BY p.ViewCount DESC