
USE CQNUOMEI
GO


SELECT * FROM gbm04

SELECT * FROM ggm01 ORDER BY gga02d DESc

SELECT * FROM gcm01 order BY GCA06D DESC


SELECT * FROM gcm04 WHERE gcd01c IN('880301',
'880306')

DELETE gcm03 WHERE gcc01c IN('880301',
'880306')

DELETE gcm01 WHERE gca01c IN('880301',
'880306')


SELECT gcd05i FROM gcm04
WHERE gcd09d >= '20160411'
GROUP BY gcd05i


SELECT * FROM gcm20
SELECT * FROM gcm04 WHERE gcd09d >= '20160411'
SELECT * FROM gcm04 WHERE gcd01c = '880075' AND  gcd09d >= '20160411'

SELECT gcd01c,case when gcd05i = 0 then + gcd06f else - gcd06f end
 FROM gcm04 WHERE gcd09d >= '20160411'
 AND gcd01c = '880075'
GROUP BY gcd01c,gcd05i,gcd06f

DELETE  gcm04 WHERE gcd09d >= '20160411'
DELETE  gcm20 WHERE gct04d >= '20160411'

UPDATE A
   SET A.gcc06f = A.gcc06f - b.amt
   
  -- SELECT A.gcc01c,a.gcc06f,b.amt
  FROM gcm03 AS A,gcm01 AS C,
  (
SELECT  gcd01c,gcd02i,sum(case when gcd05i = 0 then + gcd06f else - gcd06f end) as amt
 FROM gcm04_ WHERE gcd09d >= '20160411'
GROUP BY gcd01c,gcd02i
) AS B
WHERE c.gca00c = c.gca13d
AND c.gca01c = a.gcc01c
AND c.gca00c = a.gcc00c
AND a.gcc03i = b.gcd02i
AND b.gcd01c = a.gcc01c


print db_name()

SELECT * FROM gcm04_ WHERE gcd01c = '800020'


   SELECT A.gcc01c,a.gcc06f--,b.amt
  FROM gcm03 AS A,gcm01 AS C
  WHERE c.gca00c = c.gca13d
AND c.gca01c = a.gcc01c
AND c.gca00c = a.gcc00c
AND a.gcc03i = b.gcd02i


SELECT * FROM gcm03 

DELETE gcm03 

INSERT gcm03 SELECT * FROM gcm03_



SELECT * FROM GCM03 WHERE gcc01c = '880025'

SELECT * INTO gcm04_ FROM gcm04 
SELECT * INTO gcm20_ FROM gcm20 
SELECT * INTO gcm03_ FROM gcm03 
SELECT * INTO gcm01_ FROM gcm01

select * from gcm03 where gcc08c > '2016-04-11'

SELECT * FROM gcm01 WHERE gca01c = '800020'