BlackTDN Search

sexta-feira, 10 de maio de 2013

BlackTDN :: Transact-SQL

 

----Select Database
USE ERPProducao
GO
----Create new table and insert into table using SELECT INSERT
SELECT CTT.CTT_FILIAL AS I3_FILIAL
,CTT.CTT_CUSTO AS I3_CUSTO
,CTT.CTT_DESC01 AS I3_DESC
,CTT.R_E_C_N_O_
,CTT.D_E_L_E_T_
INTO PRI_TMP ---New Table (target)
FROM CTT010 CTT ---(source)
WHERE CTT.D_E_L_E_T_ = ' ' ---(conditional)
;
----Verify that Data in TestTable
SELECT PRI.*
FROM PRI_TMP AS PRI
ORDER BY PRI.I3_FILIAL
,PRI.I3_CUSTO
;
------ Truncate Table
TRUNCATE TABLE PRI_TMP
;
------ Insert New Rows
INSERT INTO PRI_TMP (I3_FILIAL, I3_CUSTO, I3_DESC,R_E_C_N_O_,D_E_L_E_T_)
SELECT CTT.CTT_FILIAL AS I3_FILIAL
,CTT.CTT_CUSTO AS I3_CUSTO
,CTT.CTT_DESC01 AS I3_DESC
,CTT.R_E_C_N_O_
,CTT.D_E_L_E_T_
FROM CTT010 CTT
WHERE CTT.D_E_L_E_T_ = ' '
;
----Verify that Data in TestTable
SELECT PRI.*
FROM PRI_TMP AS PRI
ORDER BY PRI.I3_FILIAL
,PRI.I3_CUSTO
;
----Update Field
UPDATE PRI_TMP SET PRI_TMP.I3_DESC = X.I3_DESC
FROM
(
SELECT CTT.CTT_FILIAL AS I3_FILIAL
,CTT.CTT_CUSTO AS I3_CUSTO
,CTT.CTT_DESC01 AS I3_DESC
,CTT.R_E_C_N_O_
,CTT.D_E_L_E_T_
FROM CTT010 AS CTT
) AS X
WHERE PRI_TMP.I3_FILIAL = X.I3_FILIAL
AND PRI_TMP.I3_CUSTO = X.I3_CUSTO
;
----Verify that Data in TestTable
SELECT PRI.*
FROM PRI_TMP AS PRI
ORDER BY PRI.I3_FILIAL
,PRI.I3_CUSTO
;
----Clean Up Database
DROP TABLE PRI_TMP
GO


Pri. Eis as instruções (todas juntas e misturadas) que tentei te passar por telefone ontem (rs). Resolvemos de outra forma (Copia pra TXT delimitado, Altera com NotePad++ e Append via TXT delimitado)


[]s
иαldσ dj

Nenhum comentário:

Postar um comentário