Snowflake Recreate table in lab doesn't work - snowflake-cloud-data-platform

I am working through Snowflake workshop lab tutorial. I am up to 7.2.4/7.2.5.
The query in 7.2.4 executes fine:
set query_id = (
select query_id
from table(information_schema.query_history_by_session (result_limit=>5))
where query_text like 'update%' order by start_time limit 1
);
However the query in 7.2.5 gives an error:
create or replace table trips as (
select * from trips before (statement => $query_id)
);
The error given is:
SQL execution internal error: Processing aborted due to error 300002:1177671206; incident 8702198.
Any thoughts on what is going wrong here?

Related

report “Window query not supported” when using state_window in TDengine

I'm using state_window syntax in TDengine database.
My SQL statement is:
select t.*
from (
select ts,
tbname as app_id,
tenant_name,
queue_code,
task_name,
sum(allocated) as allocated
from yarn
where ts > now - 6m
partition by ts,tbname,tenant_name,queue_code,task_name
) t
partition by ts, app_id, tenant_name, queue_code, task_name
state_window((CASE WHEN allocated > 100 THEN 1 ELSE 0 END));
Then I encountered an error report:
DB error: Window query not supported, since the result of subquery not
include valid timestamp column
I don't particularly understand its meaning, and how to fix the problem.

Problem getting data from linked server error in SQL

I m working in SQL and I have few tables in Oracle database from which I have to get data, so I m doing so via linked server. If I omit date filter then the query works fine but if I apply date filter then it breaks.
This query works fine.
select * from openquery([ORCL], 'select sls_value, retailer_cd, tery_cd, inv_dt
from Toc_cust_second_sls_new where cust_cd IN ( ''1-ZUT42P'' )') secSls --- This query works fine
This query breaks
select * from openquery([ORCL], 'select sls_value, retailer_cd, tery_cd, inv_dt from Toc_cust_second_sls_new where cust_cd IN ( ''1-ZUT42P'' )
and to_date(inv_dt, ''dd/mm/yyyy'') between to_date(''01/05/2020'', ''dd/mm/yyyy'') and to_date(''31/05/2020'', ''dd/mm/yyyy'')') secSls
I get this error.
OLE DB provider "OraOLEDB.Oracle" for linked server "ORCL" returned message "ORA-01861: literal does not match format string".
To filter date I can use this query as it works fine.
select * from openquery([ORCL], 'select sls_value, retailer_cd, tery_cd, inv_dt, inv_no, cust_cd from Toc_cust_second_sls_new
where cust_cd IN ( ''1-ZUT42P'' )') secSls
where convert(date,secSls.inv_dt, 101) >= '2020-05-01' and convert(date,secSls.inv_dt, 101) <= '2020-05-31'
But the problem in the above query is, it first gets all the data from oracle then it filters so there are hundreds if thousands of records which takes a lot of time.
I solved it.
I removed the conversion of inv_dt in oracle as it's data type was already Date, trying to again convert it was creating problem.
select * from openquery([ORCL], 'select sls_value, retailer_cd, tery_cd, inv_dt from Toc_cust_second_sls_new where cust_cd IN ( ''1-ZUT42P'' ) and inv_dt between to_date(''01/05/2020'', ''dd/mm/yyyy'') and to_date(''31/05/2020'',''dd/mm/yyyy'')') secSls
This query works now. Thanks guys who helped me out on comments section.

I can no longer query my view and my code fails over, Any suggestions?

I have a query that has been running for over a week with no issues.
CREATE or REPLACE VIEW VW_AF AS
select f.*
from VW_AFC f
inner join
(
SELECT Forecast, ROUTE_TO_MARKET, FORECASTCURRENCY,LEVEL,IMPORT , MAX(Version) AS maxVersion
FROM VW_AFC
GROUP BY Forecast, ROUTE_TO_MARKET, FORECASTCURRENCY,LEVEL,IMPORT
order by Forecast, ROUTE_TO_MARKET, FORECASTCURRENCY,LEVEL,IMPORT
)x
on x.Forecast = f.Forecast
and x.ROUTE_TO_MARKET = f.ROUTE_TO_MARKET
and x.FORECASTCURRENCY = f.FORECASTCURRENCY
and x.Level = f.level
and x.Import = f.Import
and x.maxversion = f.version;
Today i went to query this view and keep getting errors
--SQL execution internal error: Processing aborted due to error zz:yy; incident xx.--
I have no ideas, I know that for some reason the nested inner query is now failing but cant suss it.
Any experts have advice??
Thxs
According to your comments, I think you already found the correct approach to this error.
Whenever you see "SQL execution internal error" message, you should submit a support ticket to Snowflake. The numbers you see on the error message, can only be interpreted by Snowflake (they point an incident record). Snowflake Support will access to the incident record, see the underlying error message, and provide a workaround or a fix.

Translate SELECT DISTINCT t-sql query to DAX expression

I need to create calculate table for the report in PowerBI Desktop.
I know how to do that in t-sql but I am unable to interpret it to DAX.
So should I use t-sql and add this query using "Get Data"?
Or should I create calculate table using DAX?
Which one is more efficient?
select distinct PolicyNumber,
ReserveStatus,
case when ReserveStatus = 'Open' then 1 else 0 end as OpenStatus
from RockhillClaimsDataFeed_PBI
group by PolicyNumber,ReserveStatus
Result looks like that:
can somebody help?
This is achievable by creating a calculated table in Power BI, with similar syntax using SELECTCOLUMNS and DISTINCT.
RockhillClaimsSummary =
DISTINCT(
SELECTCOLUMNS(
RockhillClaims,
"PolicyNumber", RockhillClaims[PolicyNumber],
"ReserveStatus", RockhillClaims[ReserveStatus],
"OpenStatus", IF(RockhillClaims[ReserveStatus] = "Open", 1, 0)
)
)
Results:

Quicker way of finding duplicates in SQL Server

I'm trying to find a better way of finding duplicates in SQL Server. This took over 20 minutes to run with just over 300 million records before results started showing in the results window within SSMS. Another 22 minutes elapsed before it crashed.
Then SSMS threw this error after displaying 16,777,216 records:
An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown.
Schema:
ENCOUNTER_NUM - numeric(22,0)
CONCEPT_CD - varchar(50)
PROVIDER_ID - varchar(50)
START_DATE - datetime
MODIFIER_CD - varchar(100)
INSTANCE_NUM - numeric(18,0)
SELECT
ROW_NUMBER() OVER (ORDER BY f1.[ENCOUNTER_NUM],f1.[CONCEPT_CD],f1.[PROVIDER_ID],f1.[START_DATE],f1.[MODIFIER_CD],f1.[INSTANCE_NUM]),
f1.[ENCOUNTER_NUM],
f1.[CONCEPT_CD],
f1.[PROVIDER_ID],
f1.[START_DATE],
f1.[MODIFIER_CD],
f1.[INSTANCE_NUM]
FROM
[dbo].[I2B2_OBSERVATION_FACT] f1
INNER JOIN [dbo].[I2B2_OBSERVATION_FACT] f2 ON
f1.[ENCOUNTER_NUM] = f2.[ENCOUNTER_NUM]
AND f1.[CONCEPT_CD] = f2.[CONCEPT_CD]
AND f1.[PROVIDER_ID] = f2.[PROVIDER_ID]
AND f1.[START_DATE] = f2.[START_DATE]
AND f1.[MODIFIER_CD] = f2.[MODIFIER_CD]
AND f1.[INSTANCE_NUM] = f2.[INSTANCE_NUM]
Not sure how much faster this is, but worth a try.
SELECT
COUNT(*) AS Dupes,
f1.[ENCOUNTER_NUM],
f1.[CONCEPT_CD],
f1.[PROVIDER_ID],
f1.[START_DATE],
f1.[MODIFIER_CD],
f1.[INSTANCE_NUM]
FROM
[dbo].[I2B2_OBSERVATION_FACT] f1
GROUP BY
f1.[ENCOUNTER_NUM],
f1.[CONCEPT_CD],
f1.[PROVIDER_ID],
f1.[START_DATE],
f1.[MODIFIER_CD],
f1.[INSTANCE_NUM]
HAVING
COUNT(*) > 1

Resources