ReadVitamin

Blogging on Teradata SQL and More

7 Comments

mygif
Vaideesh Said in Tuesday, April 28th, 2009 @1:09 pm  

Can anyone tell me What is the default order of precedence of the logical operators AND, OR, NOT ?? Thanks in advance

mygif
admin Said in Thursday, April 30th, 2009 @4:52 pm  

Hi Vaideesh, Here are the rules for Order of Evaluation

A. If an expression contains more than one of the same operator, the evaluation precedence is left to right.

B. If an expression contains a combination of logical operators, the order of evaluation is as follows:

1 NOT
2 AND
3 OR

C. Parentheses can be used to establish the desired evaluation precedence.

D. The logical expressions in a conditional expression are not always evaluated left to right.

Just to add, one should avoid using a conditional expression if its accuracy depends on the order in
which its logical expressions are evaluated. For example, compare the following two expressions:

Field2/(NULLIF(Field1,0))> 112
Field1 0 AND Field2/Field1 > 112

The first expression guarantees exclusion of division by zero. The second allows the possibility of error, because the order of its evaluation determines the exclusion of zeros.

Hope this helps

mygif
stringbeans Said in Friday, June 5th, 2009 @11:54 am  

Hi!

how can I generate random integers (with decimal places) between 0 and 1 through SELECT RANDOM (0,1)

mygif
mad_about_coffee Said in Friday, June 5th, 2009 @3:46 pm  

just had the same problem stringbeans…. already got any answer about this?

mygif
admin Said in Monday, June 8th, 2009 @8:34 pm  

Hi,

While I know that you can “cast” the result of RANDOM fucntion to float or decimal and then divide it by 10 or more but I am not sure about the syntax, but here is the logic,

SELECT CAST (RANDOM ( 0, 1) as DECIMAL/FLOAT)/10 FORMAT (’9.99′) AS RANDOM_NBR_DCML

Hope that helps.

mygif
Clancy Said in Tuesday, July 7th, 2009 @6:49 pm  

I am creating a table in Teradata SQL. One of the fields (DEVICE_ID_NUMBER) is numeric, but is too large to delare as Integer (resulting in an overflow).

Hence, I am declaring it as Float, which works:

CREATE TABLE Table1 ,FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
SVC_ACCESS_ID INTEGER,
DEVICE_ID_NUMBER FLOAT,
DEVICE_END_DT DATE FORMAT ‘yyyy/mm/dd’
)
PRIMARY INDEX ( SVC_ACCESS_ID, DEVICE_ID_NUMBER )

However, I do not want the decimal places to show.
That is, instead of this: 354142020199461.00
I want to see this: 354142020199461

Can this be done? Thanks!

mygif
Clancy Said in Tuesday, July 7th, 2009 @8:02 pm  

Oops! I just realized that the following will work:

DEVICE_ID_NUMBER DECIMAL(20,0)

Thanks anyway! If you happen to have something else that works as well, then please feel free to post it. It is always interesting to see the different solutions.

Leave Your Comments Here

Popular Articles