Dynamic SQL

Database
Enthusiast

Dynamic SQL

Hi

I have a select statement which may or may not return more than 1 row

select col_nm , col_val
into returned_col_nm,returned_col_val
from tbl

If the above SQL Statement returns only 1 row then
select x , y , z
from tbl2
where returned_col_nm = returned_col_val
Else If the above SQL Statement returns more than 1 row
select x , y ,z
from tbl2
where returned_col_nm = returned_col_val
and returned_col_nm_2nd_record = returned_col_val_2nd_record
and returned_col_nm_3rd_record = returned_col_val_2nd_record
.......so on

basically i have to append a "And Clause " dynamically if the count of records in my 1st query is more than 1.

Please let me know if this is achievable in Teradata and how ?

Thanks Much in Advance!

Sam
1 REPLY
Enthusiast

Re: Dynamic SQL

Hi Sam,

Have u tried to write procedure for this.
I think it is achievable by procedure.
Try to write proc for this.

Regards,
Gander