Comparison | temporary tables
if (Not EXISTS (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Old_outid] and OBJECTPROPERTY (ID, N ' isusertable ') = 1))
Begin
Select Customerid,outid into Old_outid from t_customers
--update t_customers Set outid= ' Please enter a new work number '
*--Restore the new work number to the old work number value
UPDATE t_customers
SET T_customers.outid = Old_outid.outid
From Old_outid
WHERE Old_outid.customerid = T_customers.customerid
*/
End
SELECT * Into #dpt from (select Dpcode1+dpcode2+dpcode3 as department code, dpname1+ '/' +dpname2+ '/' +dpname3 as department name from T_departme NT where dpname1 are NOT null and dpname2 are NOT null and DPNAME3 are NOT NULL UNION ALL SELECT DPCODE1+DPCODE2+DPCODE3 as Gate code, dpname1+ '/' +dpname2 as department name from T_department where dpname1 are not null and dpname2 are NOT null and DPNAME3 is null U Nion all SELECT dpcode1+dpcode2+dpcode3 as department code, dpname1 as department name from T_department where dpname1 are not null and dpname2 I s null and DPNAME3 is null) l
SELECT CustomerID, MAX (OPDT) as last replenishment time into #ReNewCard_MaxDt
From T_renewcard
GROUP by CustomerID
SELECT department name, name as name, alias as Alias, Cardtype as card class, C.outid as new work number, O.outid as old work number, last replenishment time
From t_customers c INNER join #dpt D on D. department code =c.account INNER join #ReNewCard_MaxDt R on
R.customerid=c.customerid INNER JOIN Old_outid o on C.customerid=o.customerid
WHERE (C.cardtype in (1, 2))
drop table #dpt
drop table #ReNewCard_MaxDt
/*-For View code, function ibid, inconvenient to read and modify the update, but widely applicable.
SELECT d. department name, C.name as name, C.alias as Alias, C.cardtype as card class,
C.outid as new work number, O.outid as old work number, R. Last Replenishment Time
From t_customers C INNER JOIN
(SELECT dpcode1 + dpcode2 + dpcode3 as department code,
Dpname1 + '/' + dpname2 + '/' + Dpname3 as Department name
From T_department
WHERE dpname1 are not null and dpname2 are NOT null and
Dpname3 is not NULL
UNION All
SELECT Dpcode1 + dpcode2 + dpcode3 as department code,
Dpname1 + '/' + dpname2 as Department name
From T_department
WHERE dpname1 are not null and dpname2 are NOT null and
Dpname3 is NULL
UNION All
SELECT Dpcode1 + dpcode2 + dpcode3 as department code, dpname1 as department name
From T_department
WHERE dpname1 are not null and dpname2 are null and DPNAME3 is null)
D on D. department code = C.account INNER JOIN
(SELECT CustomerID, MAX (OPDT) as last replenishment time
From T_renewcard
GROUP by CustomerID) r on r.customerid = C.customerid INNER JOIN
Old_outid o on c.customerid = O.customerid
WHERE (C.cardtype in (1, 2))
*/