Querying using the datepart from a time stamp in a pass-through Proc SQL

后端 未结 3 2016
执笔经年
执笔经年 2021-01-27 15:33

I am trying to use the date part of a time-stamp in my where query in a db2 pass-through proc SQL code below. I tried using date and datepart functions but it wont work with thi

3条回答
  •  花落未央
    2021-01-27 16:14

    In general, you need to use the correct DB2 syntax. I don't know DB2, but this paper covers this fairly well. Specifically:

    PROC SQL; 
    CREATE TABLE ONE AS SELECT * FROM CONNECTION TO DB2 
     (SELECT A.ID, A.NAME, B.AMOUNT, B.POSTDATE 
    FROM IDS A 
    INNER JOIN BANK B 
    ON A.ID = B.ID 
    WHERE POSTDATE BETWEEN '2007-01-01-00.00.00.000000' 
     AND '2007-09-30-23.59.59.999999')
    

    So it looks like your query would be

    PROC SQL; 
       connect to db2(ssid=smtng); 
         select *  from connection to db2 
             (select *  
                 from ATable 
              where DATEPART(timestamp) > '2013-12-01-00.00.00.00000'
       FOR READ ONLY WITH UR
        );
    DISCONNECT FROM DB2;
    QUIT; 
    

    This article from IBM seems to suggest that there are other formats other than timestamp (which is what above is). So you may need to use a different one depending on the exact format.

提交回复
热议问题