Quantcast
Channel: Teradata Forums - Database
Viewing all 14773 articles
Browse latest View live

Using fields form SELECT block in QUALIFY block - forum topic by Arhimag

$
0
0

Hello!
Teradata allows to use fields from SELECT block in other blocks. 
A have two tables T1 and T2. And there is a field "a" in table T1 and in T2. And i made a new field in select block^
SELECT 
case when T1.a > T2.a then T1.a else T2.a end AS a
 
and I want to use this "a" in qualify block. I don't want to write this case again. How can I do it? Are there any special alias for fields from SELECT block?

Thank you!
 

Forums: 

How to convert UTC millisecond to Timestamp(6) - response (5) by dnoeth

$
0
0

Hi Piotr,
this is a modfied Timestamp to Unixtime calculation including centiseconds:

REPLACE FUNCTION TimeStamp_to_Unixtime_centisec (ts TIMESTAMP(6))
RETURNS BIGINT
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
SQL SECURITY DEFINER
COLLATION INVOKER
INLINE TYPE 1
RETURN 
(CAST((CAST(ts AS DATE) - DATE '1970-01-01') AS DEC(18,6)) * 86400
+ (EXTRACT(HOUR FROM ts) * 3600)
+ (EXTRACT(MINUTE FROM ts) * 60)
+ (EXTRACT(SECOND FROM ts))) * 100;

 
 

Performance Data - response (4) by imaadesi

oreplace of -> - forum topic by memostone

$
0
0

Hi,
We have an attribute containing special character shown as below, in sql assistant(TD 14) it's showing as 1st line, but when exporting to excel it's showing as 2nd line. 
After trying OREPLACE function with below, still it's not removing that special character, could you please give some suggestions?

Forums: 

Getting Error Message inside a Stored Proc Exception Handler - forum topic by RonaldBrayan

$
0
0

Hi All,

 

I'm a core-DBA, not much idea in  stored Proc's.

 

I have written a a SP with Exception CONTINUE HANDLER. My requirement is to get the Error Message from the errors if any. I have written the code as below, please let me know if this is the correct way of capturing the Error Message, or is there a better way of writing ?

 

DECLARE CONTINUE HANDLER FOR SQLSTATE '42000'

E1: BEGIN

::::some code logic here...

GET DIAGNOSTICS EXCEPTION 1 ErrMsg_value = MESSAGE_TEXT ;

SET ErrCode_value = SQLCODE ;

END E1;

 

 

May be this is simple for you guy's..Thanks in advance.

 

Forums: 

oreplace of -> - response (1) by Arparmar

$
0
0

hi ,
Do you mean  in SQL assistant Oreplace is unable to remove the special symbol ?
please check one of the below option that might be help you .

SELECT REGEXP_REPLACE ('employees ->retirment ->system' ,'[-><]','',1,0,'i') 
or 
sel otranslate  ('employees ->retirment ->system' ,'->','');
or 
sel oreplace   ('employees ->retirment ->system' ,'->','');

all the function working fine to me.
please let me know  if  i don't get you correctly.
Br,
Arun
 

BTEQ hangs for large BTEQ file - response (2) by VinnyVally

$
0
0

Hello,

After having come across the above issue again (this time with a file much larger than the 61k limit we seem to have) I've discovered that the BTEQ appears to run correctly when run from the command line manually. If the BTEQ is however run with the exact same command line command, but from a shell script (ksh), it appears to hang indefinitely.

I will still be looking for a solution to this odd issue and should I find it I will update this post with the answer.
Cheers.

Use the outcome of a query as input for a new select statement - forum topic by edgar55

$
0
0

Hi,
Ik have two tables with data. On table with forms with names such as 'Ticket' or 'change_name'. The form table has 30 columns named column1, column2, etc... and depending on the form name, one of them contains a last name. 
Form table:
Table 1
Form_name         |     column1    |        column2      |        column3 etc.
Ticket                 |     henderson  |     €350              |       Aruba
change_name    |     90210        |    Smith              |       flower
 
I have a second lookup table that tells for each form which column holds the last name (there are hundreds of forms and they change often, so hard coding is not an option). It looks like this:
Table 2
Form_name        |    last_name
Ticket                |    column1
change_name   |    column2
 
I would like to write a query to pick up the last name from Table1 using the values from Table 2.
So, something like:
select (table2.last_name) as last name from Table1
left join table2 on table1.formcode = table2.formcode
 
The desired outcome would look like:
form_name    |     last_name
Ticket             |    Henderson 
change_name |    Smith
 
I have the feeling I should use dynamic SQL, but I am not experienced and after a couple of hours of browsing forums, I thought I'd try my luck here.
 

Forums: 

oreplace of -> - response (2) by memostone

$
0
0

Hi Arun,
 
Thanks for the input. But that special character is not simply '->', it's only showing when exported to excel. I've tried to use oreplace of '0D'XC, '09'XC, '1C'XC,  X'0A', '0D0A'XC, '0A0D'xc, '0A'XC.  But no luck.

oreplace of -> - response (3) by Fred

$
0
0

Use CHAR2HEXINT function to determine the actual character value.

LOCKING TABLE table_name FOR ACCESS can be blocked by other locks - forum topic by sdc

$
0
0

Hello,
I am trying to use the following statement so I can do a dirty read on a table which has locks applied to it from other users.

LOCKING TABLE table_name FOR ACCESS

The problem is, this statement is being blocked due to the other locks.  Why?  I thought the point of the ACCESS lock was to circumvent other locks, at the risk of getting inconsistent data.
Thanks for your time.

Forums: 

LOCKING TABLE table_name FOR ACCESS can be blocked by other locks - response (1) by sdc

$
0
0

One further observation: When I instead lock the ROW for access (as below) followed by a SELECT statement, the command is not blocked.

LOCKING ROW FOR ACCESS

 

oreplace of -> - response (4) by dins2k2

$
0
0

Hi memostone
 
What is the characterset defined for the attribute? latin or unicode?
I tried the below which I coundn't see anything in the SQLA 14.10 but when I saved in the excel, it showed this arrow symbol(attached)

sel U&'#0362' uescape '#';

Even I tried to replace/traslate, it gives me Failed. 6706:  The string contains an untranslatable character. error.
Could you let us know how this untranslatable character is added in the attribute? During import or export?
 
Thanks,
Dinesh
 

LOCKING TABLE table_name FOR ACCESS can be blocked by other locks - response (2) by Arparmar

$
0
0

hi Shaun,
this statement is blocked in only one senario when we the requested table is Already having  exclusive lock.An exclusive lock on  table prevents other users from obtaining any lock on the locked object.
please check below link , might be it will help you to get clear picture .
https://forums.teradata.com/forum/enterprise/exclusive-lock

LOCKING TABLE table_name FOR ACCESS can be blocked by other locks - response (3) by sdc

$
0
0

Thanks Arparmar.  I have searched my codebase and am sure that it does not explicitly apply an exclusive lock.  Further, I am not using DDL in my codebase (which I understand implicitly applies an exclusive lock).  Are there other common operations that would apply an exclusive lock? I am doing pretty simple stuff here.


oreplace of -> - response (5) by memostone

$
0
0

@Dinesh, it cannot be translated, we got data from a different resource, sorry i'm not sure how it got loaded.
After CHAR2HEXINT function, it's showing "1A", a unrecognizable character in teradata.

oreplace of -> - response (6) by dins2k2

$
0
0

Memostone,
 
Ok. If thats the case, you can replace the unrecognizable character in the excel sheet. You will get lots of excel macros by googling or you can modify it manually. 
Please share if you have any ways to traslate it from DB side. I hope there should be a way for this :)
 
Thanks,
Dinesh

Use the outcome of a query as input for a new select statement - response (1) by Arparmar

$
0
0

hi edger,
i am not sure about dynamic SQL but it can be achieved without dynamic SQL as well.
 

CREATE TABLE col_number ( col VARCHAR(10));
INSERT INTO col_number ('col1');
INSERT INTO col_number ('col2');
INSERT INTO col_number ('col3');
INSERT INTO col_number ('col4');
INSERT INTO col_number ('col5');
INSERT INTO col_number ('col6');

SEL   A.FORM_NAME,
A.LAST_NAME
FROM  
(
SELECT
  FORM_NAME,
  B.COL AS COL_NUM,
  CASE B.COL
     WHEN 'COL1' THEN TAB.COL1
     WHEN 'COL2'   THEN TAB.COL2
WHEN 'COL3' THEN TAB.COL3
WHEN 'COL4' THEN TAB.COL4
WHEN 'COL5' THEN TAB.COL5
WHEN 'COL6' THEN TAB.COL6
      END AS LAST_NAME 
FROM FORM TAB CROSS JOIN COL_NUMBER AS B) A
INNER  JOIN  FORM_1  B
ON A.FORM_NAME=B.FORM_NAME
AND A.COL_NUM=B.LAST_NAME;

Regards,
Arun

Use the outcome of a query as input for a new select statement - response (2) by dnoeth

$
0
0

It's a horrible data model, that's why you need horrible queries :)

select frm.form_name,
   case lkp.last_name 
     when 'column1' then frm.column1
     when 'column2' then frm.column2
     when 'column3' then frm.column3
     etc.
   end
from formtable as frm join lookuptable as lkp
on frm.form_name = lkp.form_name

 

Use the outcome of a query as input for a new select statement - response (3) by edgar55

$
0
0

Spot on Dieter! Unfortunately, changing the data model will take many years and this hopefully just days :-)

Viewing all 14773 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>