teradata

How to delete records from a column which belong to a different data type?

假装没事ソ 提交于 2019-12-25 08:30:36
问题 So I inserted few records in a table manually (without using Stored procedure) and rows were fine under a column " COLMN ". Then I tried to automate it by using dynamic-SQL in stored procedure. Unfortunately I ended up appending rubbish records (entered float in a column which was meant to be Char). How can I delete these selected rubbish records which don't belong? Here is how my table looks like: ...And I want to delete those numeric records (from column " COLMN ") I planned to achieve this

How to get maximum column values across a row in Teradata sql?

大兔子大兔子 提交于 2019-12-25 06:06:46
问题 I have a table named cnst_chrctrstc_abc with 10 columns (equ_gender1 - bb_population_flag) each row which contain numeric values (count) . I want to get maximum 5 values out of each row across those 10 numeric columns. The query I have looks something like the following .. SEL FROM ( SEL SUM(CASE WHEN COALESCE(act.equ_gender1,'') = COALESCE(inact.equ_gender1,'') THEN 0 ELSE 1 END ) AS equ_gender1_chg_cnt, SUM(CASE WHEN COALESCE(act.exp_ex_bmyr1,'') = COALESCE(inact.exp_ex_bmyr1,'') THEN 0

Convert char to int TeraData Sql

♀尐吖头ヾ 提交于 2019-12-25 04:19:33
问题 I'm trying to convert a column from char (8) to integer in order to make a referential integrity with an integer. IT didn't work and I test a select in order to check the cast. Utente_cd is a char (8) column SEL CAST(UTENTE_CD AS INTEGER) FROM TABLEA Teradata produces this error: SELECT Failed. 2621: Bad character in format or data of TABLEA. Sometime the char column contains also an alphanumeric code that I should discard. 回答1: In TD15.10 you can do TRYCAST(UTENTE_CD AS INTEGER) which will

Teradata String Manipulation (Second Space)

耗尽温柔 提交于 2019-12-25 03:56:35
问题 I'm having great difficulty solving this seemingly easy task: Purpose: Create a query that eliminates the middle Initial Example Name Smith, John A Jane, Mary S I would like an output such as this: Name Smith, John Jane, Mary Any tips on how to do this with Teradata SQL I believe I solved the issue, albeit in a very poor way: SELECT SUBSTR('SMITH, JOHN A', 0, (POSITION(' ' IN 'SMITH, JOHN A') + (POSITION(' ' IN SUBSTR('SMITH, JOHN A',(POSITION(' ' IN 'SMITH, JOHN A'))+ 1,50))))) 回答1: select a

historical data load from SQL to teradata temporal table

雨燕双飞 提交于 2019-12-25 01:41:58
问题 I need to do a historical type 2 data from a SQL server table to treat temporal table. I asked this question earlier but did not ask it completely and only 1st part was mentioned in question. below is link for same: Previous Question with Answer Sorry if I am duplicating question but that thread looks dead and I can use some help here. I need have three versions of data in SQL server Version 1,2,3. e.g. Version 1 - Effective start date Effective End Date 1/1/10 1/1/11 Version 2 - Effective

Error when inserting CTE table values into physical table

為{幸葍}努か 提交于 2019-12-24 22:25:19
问题 I have a complex query that creates a master CTE_Table form other CTE_Tables. I want to insert the results of the master CTE_Table into a physical table. I'm using Teradata version 15.10.04.03 SELECT Failed. [3707] Syntax error, expected something like a 'SELECT' keyword or '(' or a 'TRANSACTIONTIME' keyword or a 'VALIDTIME' keyword between ')' and the 'INSERT' keyword. DROP TABLE dbname.physicalTablename ; CREATE MULTISET TABLE dbname.physicalTablename , NO FALLBACK , NO BEFORE JOURNAL, NO

TeradataSQL: Time to String, Add to Date and Compare to Another Time and Data

强颜欢笑 提交于 2019-12-24 20:25:32
问题 I'm trying to figure out the cleanest way to do a comparison in Teradata SQL Assistant. I have the scheduled start date (TimeStamp), the Schedule start time (varchar), actual start and end times (TimeStamp). I need to consolidate the scheduled start date and time and be able to compare it to the actual start and end date and time without modifying the original data (because it's not mine). I realize that the Scheduled Start Time [SST] is in a 24 hour time format with a AM/PM suffix, but like

Convert Military Time to Standard Time Error

风流意气都作罢 提交于 2019-12-24 18:53:23
问题 I have a data set that pulls back visit time in hour/min format (e.g. - 12:33PM would be 1233). I am trying to use the DATEPART function but it keeps giving me a syntax error stating that : "expecting something between '(' and the 'HOUR' keyword. The section below is the piece of the SQL that is giving me errors: CASE WHEN DATEPART(HOUR , VSL.VISIT_TIME) > 12 THEN DATEPART (HOUR, VSL.VISIT_TIME) -12 ELSE DATEPART (HOUR, VSL.VISIT_TIME) END AS THE_TIME I am trying to just get the hour part of

select two values and the two values with which former values have minimum distance with

不想你离开。 提交于 2019-12-24 12:53:50
问题 I have three columns Key, x1, y1 1 31 34 2 43 40 3 41 44 4 100 40 My expected output is: Key, x1, y2, closest_x1, closest_y2 1 31 34 43 40 2 43 40 41 44 3 41 44 43 40 4 100 40 41 44 what can be the simplest sql query to have the expected output? Note that both the values x1,y1 are considered while finding out the closest pair 回答1: A possible solution for your use case would to self-join the table using a NOT EXIST clause to ensure that the record being joined is the closest possible record to

Sequencing in Teradata

无人久伴 提交于 2019-12-24 11:33:00
问题 I would like to create a SELECT query that results in a view that is 30 fields long and 1 record thick. 2 records if we're counting the title. The specific part of the larger query in question is: WHERE CAST(EVENT_TIMESTAMP AS DATE) - CONTRACT_EFFECTIVE_DATE = 1 This produces the results desired - records where the days between EVENT_TIMESTAMP and CONTRACT_EFFECTIVE_DATE is 1. But I'd like this for 30 days. Something like: WHERE CAST(EVENT_TIMESTAMP AS DATE) - CONTRACT_EFFECTIVE_DATE = 1:30