When I execute the following sql, the database will be down:
select ts,e,e1,e2,e3,e4,buildid,gatewayid,meterid,ct
from ele_meters
where buildid='ba00001'and ts>='2022-11-23 00:00:00' and ts <=now
partition by tbname
limit 1;
Want to know how to solve this problem
Related
I want to filter a table based on dates starting from 2022. But I can't seem to get the code working.
this is what I have tried:
PROC SQL;
CONNECT to db2 ;
create table mytable
as select * from connection to DB2
(SELECT *
FROM mytable
where Datepart(Mydates) > '01JAN2022'd
);
DISCONNECT from db2;
quit;
Mydates has the Datetime30.6 format
Kind regards
Thanks to #Tom who mentioned it had to be in DB2 code which I didn't know.
solution:
where Mydates > '2022-01-01 00:00:00'
I am running the following query:
select TABLE_SCHEMA ||'.'||TABLE_NAME AS Schema_Table
from qsys2.systables
where table_schema = 'PTLDBA'
AND TABLE_NAME LIKE'DAILY%'
AND DATE (LAST_ALTERED_TIMESTAMP) = CURRENT DATE;
The result set is schema.table name. I need to use the result set to query the actual table
The final query would look like this:
Select * from Schema_Table limit 10;
The table name changes depending on the day. I believe a SQL Procedure would work best but I am not sure how to write it.
we're using SAS 7.13 HF1 (7.100.3.5419) (64-bit)
I'm currently looking at a post that shows how to pass a value from SAS to a database that you're connecting in to. Here is the example below. You can see they take the Macro variable StartDate and pass it into Teradata to be used in the query.
%let StartDate = 2016/01/01;
proc sql;
connect to teradata
(BULKLOAD=YES MODE=TERADATA user=&user. Password=&passwd.);
CREATE TABLE WorkTest.test AS
select * from connection to teradata
(
SELECT
TOP 10 *
FROM SomeCalendarData
WHERE SomeDate = %bquote('&StartDate.');
);
quit;
I want to go the other way.
How can I read a value from a similar query, only my DB is Netezza, and somehow pass it to a macro variable in SAS?
Thanks!
You would use the
SELECT <expression> INTO :<macro_var>'
statement. This is available in the PROC SQL query but not in the pass-through code, so it would look something like
proc sql;
connect to teradata
(BULKLOAD=YES MODE=TERADATA user=&user. Password=&passwd.);
select somedate into :my_macro_var from connection to teradata
(
SELECT somedate
FROM SomeCalendarData
WHERE id = 101;
);
quit;
See the docs here: http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1tupenuhmu1j0n19d3curl9igt4.htm
I am executing this sql statement dynamically in oracle using EXECUTE IMMEDIATE statement. But when I Do this I get an error 'missing keyword'. I have declare the RULECOUNT variable as NUMBER. When I remove the INTO statement, the sql statement appears to get executed properly.
SELECT COUNT(DISTINCT RULE_ID) INTO RULECOUNT FROM(
SELECT
distinct a.RULE_ID, Rule_Name, Applicability,
Rule_Type, KPI_NAME, BT, DT, Authorised_User,
Rule_Date_of_Creation
from vw_rule_detail_search a WHERE a.Applicability = 'No' order by a.BT
desc);
I don't know what is happening, can anyone good in oracle help me find what I am missing.
I found solution to my problem. I should not have used INTO statement in select statement while executing with execute immediate.
I should have used like this
EXECUTE IMMEDIATE statement INTO RuleCount;
Is it possible to to extract SQL queries that are saved in a table?
For example
select * from saved_queries
name | statement
queryname | 'select * from mytable where myfield = 'somevalue'
I would like to be able to do something like
select * from ( extractsomehow( 'select Statement from saved_queries where name = 'queryname') ).
Unfortunately I cannot use Java so I am restricted to SQL and XML there.
I am using Oracle 11g
If you can write a stored procedure, you could use execute immediate, something like this:
select statement into v_statement from saved_queries where ... ;
execute immediate v_statement;
Before you use dynamic SQL, think carefully about whether or not you actually need it.