Pick best filled value of multiple occurences of value combination in SQL

Advertisements I have the following piece of SQL code: select date, session_id, article_id, category from table The outcome is now something like this: date session_id article_id category 01-05 124 xyz animals 01-05 124 xyz "" 01-05 124 xyz null 01-05 456 qwert sports 01-05 456 qwert "" 01-05 456 qwert sports I want to have… Read More Pick best filled value of multiple occurences of value combination in SQL

Select rows based on desired date difference from first row by group – SQL

Advertisements I can generate a table with the following structure – in actuality, this is more than 50,000 rows long – but below example is a simplified representation: Row Account Number Date 1 1001 2011-01-10 2 1001 2011-02-01 3 1001 2011-02-20 4 1001 2011-02-22 5 2001 2011-04-11 6 2001 2012-01-01 7 2001 2012-01-30 8 2001… Read More Select rows based on desired date difference from first row by group – SQL

Snowflake JavaScript Stored Procedure Returns Success Despite Expected Failure

Advertisements I’ve recently been experimenting with Snowflake’s JavaScript stored procedures and encountered an unexpected behavior. I created a simple stored procedure as outlined in the Snowflake documentation here. Here’s the stored procedure I created: create procedure broken() returns varchar not null language javascript as $$ var result = ""; try { snowflake.execute( {sqlText: "Invalid Command!;"}… Read More Snowflake JavaScript Stored Procedure Returns Success Despite Expected Failure

SQL-Snowflake – How to count the days between dates in 2 or more rows wtih WHERE condition

Advertisements COUNTRY STORE_ID ORDER_DATE DE 990003975 2023-01-24 FR 990004963 2023-04-11 FR 990005204 2023-06-15 FR 990005204 2023-06-10 FR 990005204 2023-06-07 JP 990005210 2023-01-08 I have data presented like the table above. I need a way to add a column that shows me the difference in days between the dates of the same STORE_ID, ordering them in… Read More SQL-Snowflake – How to count the days between dates in 2 or more rows wtih WHERE condition

How to pass parameter in snowflake stored procedure

Advertisements I am trying to pass Company_name as parameter, it being called twice in the SQL Query. First it is being replaced by value but for second instance value is getting passed. UPPER(COMPANY_NAME)=UPPER(”Company_name”) . CREATE OR REPLACE PROCEDURE DEVELOPMENT.PUBLIC.PDL_SKILLS_DATA_SP(Company_name VARCHAR) returns varchar LANGUAGE SQL as $$ DECLARE query STRING; date_str STRING; time_str STRING; BEGIN SELECT… Read More How to pass parameter in snowflake stored procedure

snowflake sql i need to generate column with 0000001 and end with as increment by 0000001

Advertisements i have tried with sequence in snowflake but i need my first values need to start with 0000001 and end with increment as of RecordID 0000001 0000002 0000003 0000004 0000005 0000006 0000007 0000008 0000009 0000010 0049443 –like this …but i am not able to achieve by sequence in snowflake? drop TABLE foo CREATE OR… Read More snowflake sql i need to generate column with 0000001 and end with as increment by 0000001