This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=query('2014_Q3'!$A$2:$B$8; "select B where A ='"&A2&"' ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
say you have a spreadsheet formatted thusly (for instance a survey form): | |
timestamp, user, question | |
'2013-01-01', person1, Y | |
'2013-01-01', person2, Y | |
'2013-01-01', person3, N | |
and you want to get a count, by day, of the responses like: | |
Date, Y, N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- the utc value | |
declare @utc datetime = '20/11/2014 05:14' | |
-- the local time | |
select DATEADD(hh, DATEDIFF(hh, getutcdate(), getdate()), @utc) | |
--Conversely (to go from local to UTC) | |
DECLARE @LOCAL DATETIME = getdate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This method has the best performance over other methods normally used (union all, etc)*/ | |
SELECT TOP 50 | |
INV.PONUMBER | |
,INV.KEYINDATE | |
,INV.PAIDDATE | |
,INV.DATE | |
, | |
(SELECT | |
MAX(LASTUPDATEDATE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER FUNCTION [dbo].[UTC_TO_LOCAL_TIME_W_DST_ADJUST] (@DTTM DATETIME2 -- In UTC | |
) | |
RETURNS DATETIME2 | |
AS | |
BEGIN | |
--DECLARE @DTTM AS DATETIME2 = '01-Mar-2015 09:01:00'; | |
DECLARE @LOCAL AS DATETIME2; | |
DECLARE @DT_YEAR AS VARCHAR(4) = DATEPART(YEAR,@dttm); | |
DECLARE @STARTDLS AS DATETIME2 = '01-Mar-' + @DT_YEAR; | |
DECLARE @STOPDLS AS DATETIME2 = '01-Nov-' + @DT_YEAR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import multiprocessing | |
import random | |
import time | |
from services import logger | |
LOG = logger.get_logger(os.path.basename(__file__)) | |
proc_name = 'Parallel Processing Example using multiprocessing module' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create | |
--drop | |
view dw.dim_date_vw as | |
WITH nums AS ( | |
SELECT TOP 15000 row_number() over ( | |
PARTITION BY NULL order by id) n | |
FROM l_browser -- or some other large table; | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE VIEW dw.dim_time_vw AS | |
with nums AS ( | |
SELECT TOP 86400 | |
row_number() over ( | |
PARTITION BY NULL ORDER BY id) AS num | |
FROM l_browser) | |
SELECT | |
to_char( | |
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'HH24MISS') AS time_key, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Just use FIRST_VALUE. LAST_VALUE takes more coding (in SQL Server) to get the same thing done, such as the inclusion of a ROWS BETWEEN clause: | |
(Please note that this article applies to SQL Server. Redshift requires you to have a window function regardless of which method you use) | |
The below query tries to get the 'most recent' value without having to join back on itself. | |
Two methods, last_value and first_value are used in the attempt: | |
*/ | |
WITH DATES_EXAMPLE | |
AS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO [YOURLINKEDSERVER].[YOURDB].[DBO].YOURTABLE | |
SELECT | |
* | |
,cast('2017-05-20' as date) | |
FROM OPENROWSET('MSDASQL' | |
, 'Driver={Microsoft Access Text Driver (*.txt, *.csv)}; | |
DBQ=C:\first_directory\second_directory\' | |
, 'select * from "your_file.csv"') |
OlderNewer