BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

Hi all, I am trying to run a sql pass thru query with ODBC connection to Teradata but it seems the count function is not supported by this engine. I tried a different approach by removing the count function outside of the pass thru query and it ran well. 

 

I want to find out 1) Is there a better/alternative way to accomplish the same goal and 2) why count function is not supported by the odbc engine?

Below are the codes and error message for both approach.

 

Approach 1 - this gives me error message

 

PROC SQL;
  CONNECT TO teradata(user=&tduid password=&tdpwd server=axb connection=global mode=teradata fastload=yes fastexport=yes);
  CREATE TABLE inventory AS
    SELECT * 
      FROM CONNECTION TO teradata
        ( SELECT  
          count(inventory) as inv_count, 
          region                                   

        FROM      warehouse.inventory                                                                                                                      
          WHERE sale_date = '2020-10-01'                                                     

          GROUP BY region
        );
ERROR: At least one of the columns in this DBMS table has a datatype that is not supported by this engine.

 

 

Approach 2- this works but I wonder a better/alternative way because in reality, I have a lot more fields and tables.

 

PROC SQL;
  CONNECT TO teradata(user=&tduid password=&tdpwd server=axb connection=global mode=teradata fastload=yes fastexport=yes);
  CREATE TABLE inventory AS
    SELECT count(inventory) as inv_count, 
      region
    FROM CONNECTION TO teradata
      ( SELECT        
inventory, region FROM warehouse.inventory WHERE sale_date = '2020-10-01' ) GROUP BY region;

NOTE: Table work.inventory created, with 131 rows and 15 columns.
NOTE: Teradata connection: TPT FastExport has read 38112 row(s).

 

 

1 ACCEPTED SOLUTION
4 REPLIES 4
ChrisNZ
Tourmaline | Level 20
ERROR: At least one of the columns in this DBMS table has a datatype that is not supported by this engine.

This tells me that variable INV_COUNT should probably be created as a datatype that SAS supports.

See here

 

LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

Thanks ChrisNZ. Actually in my production code, I do have cast(variable1 as int) as variable1, cast(variable2 as char(5)) as variable2, etc. The inventory variable does have datatype that SAS supports. The issue appears to have something to do with the count function because no matter what variable I put inside the count function, i am getting the same error message. 

LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

This works. Since Inventory is a character field, I did not even though about casting it to INT for the count function.

Thanks a lot for this great tip.

CAST(COUNT(INVENTORY) AS INT) AS INV_COUNT

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 844 views
  • 1 like
  • 3 in conversation