update multiple columns into single or one columns in sql
begin tran
CREATE TABLE #TempAdd
(
DealerId int,
MainAddress varchar(1000)
)
insert into #TempAdd
SELECT DealerId ,
DealerName + '<br/>' +
CASE
WHEN Address1 is null THEN ''
ELSE Address1 +' <br/>'
END
+
CASE
WHEN Address2 is null THEN ''
ELSE Address2 +' <br/>'
END
+
CASE
WHEN Address3 is null THEN ''
ELSE Address3 +' <br/>'
END
+
CASE
WHEN Address is null THEN ''
ELSE Address +' <br/>'
END
+ CASE
WHEN PINCode is null THEN ''
ELSE PINCode +' <br/>'
END
+ CASE
WHEN StateName is null THEN ''
ELSE StateName +' <br/>'
END as MainAddress
from dealer
UPDATE dealer
SET dealer.MainAddress=#TempAdd.MainAddress
FROM dealer, #TempAdd
WHERE dealer.DealerId = #TempAdd.DealerId
select * from dealer
--commit
--rollback
begin tran
CREATE TABLE #TempAdd
(
DealerId int,
MainAddress varchar(1000)
)
insert into #TempAdd
SELECT DealerId ,
DealerName + '<br/>' +
CASE
WHEN Address1 is null THEN ''
ELSE Address1 +' <br/>'
END
+
CASE
WHEN Address2 is null THEN ''
ELSE Address2 +' <br/>'
END
+
CASE
WHEN Address3 is null THEN ''
ELSE Address3 +' <br/>'
END
+
CASE
WHEN Address is null THEN ''
ELSE Address +' <br/>'
END
+ CASE
WHEN PINCode is null THEN ''
ELSE PINCode +' <br/>'
END
+ CASE
WHEN StateName is null THEN ''
ELSE StateName +' <br/>'
END as MainAddress
from dealer
UPDATE dealer
SET dealer.MainAddress=#TempAdd.MainAddress
FROM dealer, #TempAdd
WHERE dealer.DealerId = #TempAdd.DealerId
select * from dealer
--commit
--rollback
Comments
Post a Comment