2012-08-17

TSQL - Scientific notation arithmetic warning


select 2E
union all select 3E
union all SELECT 2E-3E --> Doing 2E-3, ingnoring the extra "E".
union all select (2E)-(3E)
;
/*
2
3
0.002
-1
*/




2012-08-15

Teradata - How to rename a field or column


ALTER TABLE
DATABASE_NAME_HERE.TABLE_NAME_HERE
RENAME
CURRENT_FIELD_NAME_HERE
TO
NEW_FIELD_NAME_HERE
;

2012-08-08

TSQL - Dense rank vs rank vs row number


select
       T1.Field1
       , DENSE_RANK() over( order by Field1 asc ) as DenseRank
       , RANK() over( order by Field1 asc ) as DenseRank
       , ROW_NUMBER() over( order by Field1 asc ) as RowNumber
from
       (
              select 'a' as Field1
              union all select 'a'
              union all select 'a'
              union all select 'b'
              union all select 'b'
              union all select 'c'
              union all select 'd'
       ) as T1
;

2012-08-07

SSRS - Data alert grayed out, disabled

SSRS 2012
Sharepoint 2010 Foundation


"If the New Data Alert option is grayed, the report data source is configured to use integrated security credentials or prompt for credentials. To make the New Data Alert option available, you must update the data source to use stored credentials or no credentials."
http://stackoverflow.com/questions/9680419/data-alerts-disabled-in-sharepoint-2010-installed-in-integrated-mode-with-ssrs

TSQL - Comma formatted number from varchar to float


select distinct
       FIELD_NAME_HERE
       , cast(
              case
                     -- If the entire field is a dash, then turn it to null
                     -- If it is null, then keep it as null
                     when
                           FIELD_NAME_HERE='-'
                           or FIELD_NAME_HERE is null
                     then
                           null
                     -- If the cell has an actual value
                     else
                           -- Comma to nothing
                           replace(
                                  -- Ending parenthesis to nothing
                                  replace(
                                         -- Starting parenthesis with a minus sign
                                         replace(FIELD_NAME_HERE,'(','-')
                                         , ')'
                                         , ''
                                  )
                                  ,','
                                  , ''
                           )
              end
              as float
       ) as FIELD_NAME_HERE_NEW
from
       DATABASE_NAME_HERE.SCHEMA_NAME_HERE.TABLE_NAME_HERE
;