CREATE TABLE #E ( ID INT , NAME VARCHAR(20), RESULT VARCHAR(20) ) INSERT INTO #E VALUES (1,'DOMAIN','marka') INSERT INTO #E VALUES (1,'EXTENSION','.com') INSERT INTO #E VALUES (1,'TYPE','WEB') SELECT * FROM #E Declare @DomainName varchar(20) = '' --How can I put the values(RESULT) in a result side by side SELECT RESULT FROM #E WHERE ID=1 AND NAME IN ('DOMAIN','EXTENSION')
How can I put the values(RESULT) in a result side by side How can I do it? –> Set @DomainName = ‘marka.com’
@DomainName = ‘marka.com’ –How do I add
Advertisement
Answer
DECLARE @DomainName varchar(20) = '' SELECT @DomainName = (DOMAIN + EXTENSION) FROM ( SELECT * FROM #E WHERE ID=1 AND NAME IN ('DOMAIN','EXTENSION') ) as main PIVOT ( MAX(RESULT) FOR NAME IN ([DOMAIN],[EXTENSION]) ) piv SELECT @DomainName