View previous topic :: View next topic
|
Author |
Message |
ravindra.vadali
New User
Joined: 30 Jan 2012 Posts: 34 Location: USA
|
|
|
|
Hi,
This is the first time I am addressing this forum so please excuse me if my post is irrelevant & I would be happy to receive the stones (smaller please) if you throw at me
Here goes my requirement:
I have to INSERT a row in a table, and I have to alternate the values of a particular column to either a zero or one & either to Y or N depending on the values that are retrieved from a select stament, so I used a CASE statement inside the SET clause of the INSERT statement and designed the query as follows:
Code: |
INSERT INTO AGREMENT_TABLE CSR_I
(
CSR_I.CTC_ADR_TYP_ID,
CSR_I.AGREEMENT_COUNT,
CSR_I.HAS_QUOTES_I,
)
VALUES
(
12345,
CASE 1 /*FIND ANY POLICIES*/ /*AGREEMENT_COUNT*/
WHEN (
SELECT COUNT(*)
FROM POLICY_TABLE CAG_POL
JOIN MASTER_TABLE AGR_POL
ON AGR_POL.AGREEMENT_ID = CAG_POL.AGREEMENT
WHERE AGR_POL.AGREEMENT_TYPE = 'POLICY'
AND CAG_POL.CUSTOMER_ID = CURSOR_CUS:CUSTOMER_ID
AND CAG_POL.NMD_ISU_ODR_NB > 0
) > 0
THEN 1
ELSE 0
END,
CASE 2 /*FIND ANY QUOTES*/ /*HAS_QUOTES_I*/
WHEN (
SELECT COUNT(*)
FROM POLICY_TABLE CAG_POL
JOIN MASTER_TABLE AGR_POL
ON AGR_POL.AGREEMENT_ID = CAG_POL.AGREEMENT
WHERE AGR_POL.AGREEMENT_TYPE = 'QUOTE'
AND CAG_POL.CUSTOMER_ID = CURSOR_CUS:CUSTOMER_ID
AND CAG_POL.NMD_ISU_ODR_NB > 0
) > 0
THEN 'Y'
ELSE 'N'
END
)
|
I know you would suggest me to run it in a test environment but unfortunately I don't have a test environment to run this so I am looking foward for your suggestions as to whether this query would work or should I bring the case logic out of the INSERT statement and then write two different INSERT statements which will be qualified based on the CASE logic.
Once again my sincere apologies if I didn't address my problem correctly or misquoted the details. I will more than happy to provide any details you need.
Thanks,
Ravi |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
I would be happy to receive the stones (smaller please) if you throw at me |
bigger are better, smaller stones tend to get in Your eyes |
|
Back to top |
|
|
ravindra.vadali
New User
Joined: 30 Jan 2012 Posts: 34 Location: USA
|
|
|
|
Hi All,
I think I got my answer, CASE statement works in SET clause of the INSERT.
Thanks a many for your patience |
|
Back to top |
|
|
|