Q&A for professional and enthusiast programmers
DECLARE @siteName nvarchar DECLARE @getSiteName nvarchar SET @getSiteName = 'INSERT INTO ' + @siteName + ' VALUES(''DB_INFO(db_id())'')' EXEC(@getSiteName) SELECT @siteName, posts.Id AS [Post Link], (LEN(posts.Body) - LEN(REPLACE(posts.Body,'https://','')))/8 +(LEN(posts.Body) - LEN(REPLACE(posts.Body,'http://','')))/7 AS 'Links', (CASE WHEN posts.PostTypeId=2 THEN 'A' ELSE 'Q' END) AS 'Type', (CASE WHEN posts.PostTypeId=2 THEN questions.Tags ELSE posts.Tags END) AS 'Tags' FROM Posts posts LEFT JOIN Posts questions ON posts.ParentId=questions.Id WHERE posts.OwnerUserId=##UserId## ORDER BY Links DESC