2012-07-31

Teradata - String functions sampler


select distinct

      -- Concatenation
      'string 1' || ' string 2' as StringConcatenation
      , '[' || '   asdf   ' || ']' as ConcatenationWithSpaces

      -- Position and length
      , position( '_' in 'hamburgers_hot dogs' ) as PositionFound
      , position( 'a' in 'qwer' ) as PositionNotFound
      , position( 'a' in null ) as PositionInNull
      , lower( 'ABCdef' ) as LowerCase
      , upper( 'ABCdef' ) as AnUpperCase
      , character_length( 'asdf' ) as CharacterLength

      -- Trimming
      , '[' || trim( '   asdf    ') || ']' as DefaultTrim
      , '[' || trim( leading  ' ' from '  asdf') || ']' as TrimLeading
      , '[' || trim( trailing ' ' from 'asdf  ') || ']' as TrimTrailing
      , '[' || trim( both ' ' from '   asdf  ') || ']' as TrimBoth
      , '[' || trim( leading '0' from '0001230') || ']' as TrimLeadingZeroes
      , trim( leading '0' from '001234560' ) as TrimLeadingZeroes2
      , '[' || trim( both '0' from '0001230') || ']' as TrimZeroes

      -- Casting and formatting
      , CAST(123456789.00 AS FORMAT 'G999999999D99') as Casting
      , 123456 ( FORMAT 'G-(10)D9(2)' ) as AFormat

      -- Substring
      , substr( 'asdf', 3, 3 ) as Substring3
      , substr( 'asdf', 1, 3 ) as Left3
      , substring( 'asdfxyz' from CHARACTER_LENGTH( 'asdfxyz' ) -2 FOR 3) as Right3
      , substring( '0123456789ABCDEF' from CHARACTER_LENGTH( '0123456789ABCDEF' ) -11 FOR 12) as Right12

;

2012-07-27

Teradata - Fixing the "name requires more than 30 bytes" error

This happened to me while loading data using Multi-Load, but also through other Teradata OleLoad methods (version 13.10).

Make sure you:

  1. Are not loading into a table with a name longer than 30 characters.
  2. Each of your fields are at or below 30 characters in length.
  3. Your fields do not contain spaces or any strange character... only use letters and numbers.

2012-07-17

TERADATA - Adding and dropping multiple fields


alter table DATABASE_NAME.TABLE_NAME
add FIELD1_NAME varchar(200) null
, add FIELD2_NAME varchar(200) null
;
  

alter table DATABASE_NAME.TABLE_NAME
drop FIELD1_NAME
,drop FIELD2_NAME
;

TERADATA - Adding and dropping a field


alter table DATABASE_NAME.TABLE_NAME
add FIELD_NAME varchar(200) null
;

alter table DATABASE_NAME.TABLE_NAME
drop FIELD_NAME
;

2012-07-06

TSQL - Moving the master database

Moving the master Database (SQL Server 2012)



To move the master database, follow these steps.
  1. From the Start menu, point to All Programs, point to Microsoft SQL Server, point to Configuration Tools, and then click SQL Server Configuration Manager.
  2. In the SQL Server Services node, right-click the instance of SQL Server (for example, SQL Server (MSSQLSERVER)) and choose Properties.
  3. In the SQL Server (instance_name) Properties dialog box, click the Startup Parameters tab.
  4. In the Existing parameters box, select the –d parameter to move the master data file. Click Update to save the change.
    In the Specify a startup parameter box, change the parameter to the new path of the master database.
  5. In the Existing parameters box, select the –l parameter to move the master log file. Click Update to save the change.
    In the Specify a startup parameter box, change the parameter to the new path of the master database.
    The parameter value for the data file must follow the -d parameter and the value for the log file must follow the -l parameter. The following example shows the parameter values for the default location of the master data file.
    -dC:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\master.mdf
    -lC:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
    If the planned relocation for the master data file is E:\SQLData, the parameter values would be changed as follows:
    -dE:\SQLData\master.mdf
    -lE:\SQLData\mastlog.ldf
  6. Stop the instance of SQL Server by right-clicking the instance name and choosing Stop.
  7. Move the master.mdf and mastlog.ldf files to the new location.
  8. Restart the instance of SQL Server.
  9. Verify the file change for the master database by running the following query.
    SELECT name, physical_name AS CurrentLocation, state_desc
    FROM sys.master_files
    WHERE database_id = DB_ID('master');
    GO


Source:
http://msdn.microsoft.com/en-us/library/ms345408.aspx

SharePoint 2010 - Installing on SQL Server 2012

This is not a detailed 101 on how to install it, but on how to troubleshoot a problem during the installation. The error messages I received cited the following two phrases: "System.Security.Cryptography.CryptographicException" and "Keyset does not exist".

The issue got solved by making the folder "C:\Users\All Users\Microsoft\Crypto\RSA\MachineKeys" not read-only, and granting full access to the NETWORK SERVICE account to it.

Reference:
http://www.lazyasscoder.com/Article.aspx?id=73&title=Error%3a+Error%3a+System.Security.Cryptography.CryptographicException%3a+Keyset+does+not+exist+or+Access+is+denied