teradata

teradata sql pivot multiple occurrences into additional columns

删除回忆录丶 提交于 2019-12-18 02:48:01
问题 I have something like this: ID Result 1 value1 2 value1 2 value2 3 value1 4 value1 4 value2 4 value3 And I'd like to return something like this: ID Result1 Result2 Result3 1 value1 2 value1 value2 3 value1 4 value1 value2 value3 I've searched on pivots and concats and breaks and I just can't find a simple, sensible solution. TIA 回答1: Unfortunately Teradata doesn't have a PIVOT function but you can use an aggregate function with a CASE expression to get the result. select id, max(case when seq

Can we delete duplicate records from a table in teradata without using intermediate table

家住魔仙堡 提交于 2019-12-17 22:01:32
问题 Can we delete duplicate records from a multiset table in teradata without using intermediate table. Suppose we have 2 rows with values 1, 2, 3 and 1, 2, 3 in my multiset table then after delete i should have only one row i.e. 1, 2, 3. 回答1: You can't unless the ROWID usage has been enabled on your system (and probablity is quite low). You can easily test it by trying to explain a SELECT ROWID FROM table; Otherwise there are two possible ways. Low number of duplicates: create a new table as

How to execute dynamic SQL in Teradata

筅森魡賤 提交于 2019-12-17 21:33:19
问题 Is there any way to submit dynamically generated SQL to Teradata? I've written a query that will create the code to denormalize a table. Right now, I am pulling the code down to my client (SAS) and resubmitting it in a second step. I am not familiar with either Teradata macros or procedures; would something like that work? To illustrate, I have a table defined like this: create multiset table MYTABLE ( RECID integer generated always as identity ( start with 1 increment by 1 minvalue

EXTRACT the date and time - (Teradata)

不问归期 提交于 2019-12-14 03:59:50
问题 I am trying to extract the date and time from a field in Teradata. The field in question is: VwNIMEventFct.EVENT_GMT_TIMESTAMP Here is what the data look like: 01/02/2012 12:18:59.306000 I'd like the date and time only. I have tried using EXTRACT(Date , EXTRACT(DAY_HOUR and a few others with no success. DATE_FORMAT() does not appear to work since I'm on Teradata. How would I select the date and time from VwNIMEventFct.EVENT_GMT_TIMESTAMP ? 回答1: If the datatype of EVENT_GMT_TIMESTAMP is a

Trying to cast date and time in Teradata

╄→尐↘猪︶ㄣ 提交于 2019-12-14 02:42:51
问题 I'm selecting from a table with a timestamp(6) data type. I would like to get the date and time, to the minute, like so: Currently the data look like this: 03/10/2014 21:54:47.690000 I would like to select so that the result looks like this: 03/10/2014 21:54:47 I tried this: SELECT CAST(EVENT_GMT_TIMESTAMP AS DATE) || (EVENT_GMT_TIMESTAMP AS TIME) AS theDate, SUM(VwNIMEventFct.DWELL_MINUTES) AS totalDwellMins FROM RDMAVWSANDBOX.VwNIMEventFct WHERE EXTRACT(MONTH FROM EVENT_GMT_TIMESTAMP) = 4

VBA Copy & Paste 3000 rows

江枫思渺然 提交于 2019-12-14 02:41:10
问题 my code below, whoch I've copied from a Yahoo Developers articles and changed accordingly, for Query, I want to copy and paste 2999 rows of insert statements from excel to Teradata. My current way doesn't copy and paste the entire range. If I swap this for: Cells(1, 1) & " " & Cells(2, 1) & " " & Cells(3, 1)....etc. until Cells(2999), it would work. A clever, simpler way of doing this please? As an aside, would you recommend an alternative method of inserting 2999 rows. The tables are already

DECIMAL Types in Teradata

拜拜、爱过 提交于 2019-12-14 00:36:13
问题 Can somebody please explain the following result I get in Teradata: SELECT TYPE(CAST (2.3 AS DECIMAL(18,4)) * CAST (2.3 AS DECIMAL(18,4)) ) The result is: DECIMAL(18,8) I was expecting DECIMAL(18,4) 回答1: Every DBMS has it's own rules regarding calculations involving Decimals. Teradata's basic rules are: When you add/substract/divide DECIMALs the resulting fractional precision is the greater of both operands, e.g. dec(10,2) + dec(10,4) = dec(xx,4) But when you multiply the fractional digits

Turning a Comma Separated string into individual rows in Teradata

好久不见. 提交于 2019-12-13 23:04:23
问题 I read the post: Turning a Comma Separated string into individual rows And really like the solution: SELECT A.OtherID, Split.a.value('.', 'VARCHAR(100)') AS Data FROM ( SELECT OtherID, CAST ('<M>' + REPLACE(Data, ',', '</M><M>') + '</M>' AS XML) AS Data FROM Table1 ) AS A CROSS APPLY Data.nodes ('/M') AS Split(a); But it did not work when I tried to apply the method in Teradata for a similar question. Here is the summarized error code: select failed 3707: expected something between '.' and

How to tokenize a string and assign tokens to column in Teradata?

眉间皱痕 提交于 2019-12-13 18:33:32
问题 I have multiple strings of the form {key1=value, key2=value2, key3=value3 ...} with a known set of keys. The key names are set and known, with only the values changing between records. I would like to tokenize the string with the space delimiter as my tokenizing character then strip off the key names and assign each one to a column in sequential order. Is this something I can do in-database in teradata 15? 回答1: Starting with TD14 there's NVP to extract data from name-value-pairs, e.g. NVP(col

Converting date to character format in SQL

此生再无相见时 提交于 2019-12-13 07:19:57
问题 I'm trying to convert a date format stored m/d/yyyy to a 'yyyymmdd' character format, without the need to cast the date column every time I want to use the column in my query. Currently I'm casting and formatting dates as chars: ((cast(cast(invitation_date as CHAR(8)) as date format 'YYYYMMDD')) . Is there a way to convert the data column once and call the converted character value later in the query? I'm using Teradata in Aqua Data Studio 13.0.3. 回答1: If source is a DECIMAL yyyymmdd you can