Question

I'm still getting to grips with SQL. I took a bit of time and managed to construct the following query.

I then selected COUNT(*) WHERE activePU = 1 and the result was 0. I know that there should be many thousands.

I looked through the view and noticed that all the cells under activePU are blank.

Every record should have 0 or 1, there should not be empty ones. But they are all empty. Is it apparent why from my syntax?

I suspect that the problem is with my syntax since I'm a little less experienced.

UPDATE rdmatblsandbox.TmpNIMSalesForceDB
SET activePU = 
                CASE WHEN
                (TmpNIMSalesForceDB.SUBSCRIPTION_END_DATE > CURRENT_DATE OR TmpNIMSalesForceDB.SUBSCRIPTION_END_DATE IS NOT NULL) AND
                TmpNIMSalesForceDB.SERVICE_ACTIVATION_DATE < CURRENT_DATE AND
                TmpNIMSalesForceDB.ROGERS_BILLING_SYSTEM IS NOT NULL
                THEN 1
                ELSE 0
                END
Was it helpful?

Solution

"The field type is varchar(1)"

When it's a VarChar you should write a string and not a number, '0' and '1' instead of 0 and 1.

There's an automatic typecast from byteint to varchar which results in ' 0' which is then silently truncated to ' '.

But why do you use VarChar(1)? There's a two byte overhead for VarChars, so you better go with a CHAR(1). Or use a BYTEINT or DECIMAL(1), both need a single byte for storage and you won't have problems with automatic typecasts...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top