1
What would the following code look like MySQL
in SQL Server 2008
:
desc `TABLE 2`;
alter table `TABLE 2` add column `COLL 44` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 45` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 46` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 47` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 48` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 49` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 50` varchar(20) DEFAULT NULL;
alter table `TABLE 2` add column `COLL 51` varchar(20) DEFAULT NULL;
select * from `TABLE 2`;
update `TABLE 2` AS T2
INNER JOIN `TABLE 1` AS T1 ON T1.`COL 1` = T2.`COL 1` -- N3 FILIAL
AND T1.`COL 2` = T2.`COL 2` -- N3_CBASE
AND T1.`COL 3` = T2.`COL 3` -- N3_ITEM
AND T1.`COL 11` = T2.`COL 8` -- N3_CCDEPRE
SET
T2.`COL 44` = T1.`COL4`, -- N3_TIPO
T2.`COL 45` = T1.`COL8`, -- N3_CUSTOBEM
T2.`COL 46` = T1.`COL18`, -- N3_VORIGI
T2.`COL 47` = T1.`COL19`, -- N3_TXDEPR1
T2.`COL 48` = T1.`COL33`, -- N3_TVRDACM1
T2.`COL 49` = T1.`COL59`, -- N3_FIMDEPR
T2.`COL 50` = T1.`COL79`, -- N3_CLV
T2.`COL 58` = T1.`COL16`; -- N3_DINDEP
SELECT *
FROM `TABLE 2` AS T2
WHERE
T2.`COL 44` IS NOT NULL OR
T2.`COL 45` IS NOT NULL OR
T2.`COL 46` IS NOT NULL OR
T2.`COL 47` IS NOT NULL OR
T2.`COL 48` IS NOT NULL OR
T2.`COL 49` IS NOT NULL OR
T2.`COL 50` IS NOT NULL OR
T2.`COL 51` IS NOT NULL
Do you have a table with space in the name? That’s very wrong
– Sorack
@Sorack yes, I went up a CSV and it created automatic table name as TABLE 2, so the
ran right on mysql, problem I need to run on SQL Server.
– Gustavo Freire