Variable for yesterday's date in SSIS - ssis-2012

I have declared a variable called FileName1 in my package with the value -
"Exchange_"+(DT_WSTR,4) DATEPART( "YEAR", GETDATE() )+"-"+
RIGHT( "0"+(DT_WSTR,2) DATEPART( "month" , GETDATE()) , 2) +"-"+
RIGHT( "0"+(DT_WSTR,2) (DATEPART( "day", GETDATE() )-1) , 2 ) +
".txt".
What it does is it takes yesterday's date. But if I click on the Evaluate Expression on 1st day of the month (say 1st December), instead of showing "Exchange_2015-11-30.txt", its showing "Exchange_2015-12_00.txt". How can I fix this?

You need to do it like the following:
"Exchange_"+ (DT_WSTR,4) DATEPART("yyyy", DATEADD( "d", -1, getdate() ))+"-"+ (DT_WSTR,2) DATEPART("mm", DATEADD( "d", -1, getdate() )) +"-"+ (DT_WSTR,2)DATEPART("dd", DATEADD( "d", -1, getdate() )) + ".txt"

Related

Google sheets get empty cells next to each other

Link: https://docs.google.com/spreadsheets/d/1hCG6jjGSGWMn5kBkDfcoTJkZ2eCC5SRvHWMFTBp_6OE/edit?usp=sharing
I want to return "Yes" or "No" results in column N when there are empty cells next to each other in the range B:M
And column O counts the number of times there are empty cells next to each other.
Thank you.
use in O2:
=INDEX(LEN(SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(IF(REGEXMATCH(TRIM(
SPLIT(FLATTEN(QUERY(TRANSPOSE(IF(B2:M5="", "×", "¤")),,9^9)),
"¤")), "× ×"), 1, )),,9^9)), " ", )))
use in N2:
=INDEX(IF(O2:O=0, "No", "Yes"))

Google sheets ArrayFormula with IMPORTRANGE always return same result

I have a Google Sheet that imports column "L" from another file based on the row number
=ArrayFormula(
IF(LEN(K:K),
if( ROW(L:L) = 1,
"Date",
IMPORTRANGE("https://docs.google.com/spreadsheets/d/123456123456lkjjj","Sheet1!D" & M1:M)
),""
)
)
other file (Sheet1)
The problem always return the first result
Try this:
=ARRAYFORMULA(
IFS(
ROW(L:L) = 1,
"Date",
K:K = "",,
True,
IFNA(VLOOKUP(
M:M,
{
SEQUENCE(ROWS(IMPORTRANGE("https://docs.google.com/spreadsheets/d/123456123456lkjjj", "Sheet1!D:D"))),
IMPORTRANGE("https://docs.google.com/spreadsheets/d/123456123456lkjjj", "Sheet1!D:D")
},
2,
))
)
)
IMPORTRANGE works once inside ARRAYFORMULA, so it is not possible to call it in a loop. But you can get everything with it and then loop through it.

lookup on date ranges in google spreadsheet

I have a google spreadsheet which looks like this. Note that KeyColumn values are from a finite pool.
StartDate EndDate KeyColumn
01/01/2016 05/01/2016 Key1
05/01/2016 10/01/2016 Key2
11/01/2016 20/01/2016 Key1
They are sorted. Next StartDate is greater than or equal to the current EndDate.
What I want to do is creating the following sheet with a kind of lookup. Each key column can be created manually.
Date Key1 Key2
01/01/2016 True False
02/01/2016 True False
03/01/2016 True False
04/01/2016 True False
05/01/2016 True True
06/01/2016 False True
02/01/2016 is True for Key1 because it is in the range of the first row in the first table which has the value Key1.
05/01/2016 is True for Key1 and Key2 because it is in the range of the first row and the second row.
Is this possible in google spreadsheet without using any scripts? I couldn't find a way.
This can be accomplished with creative use of the filter and count functions:
i used query function to solve that the formula
=iferror(hlookup(B$8,transpose( QUERY({arrayformula(days($A$2:$B$4,)),$C$2:$C$4},"select Col3 where Col1<="& days($A9,) &" and Col2>= " & days($A9,) ,-1)),1,False)=B$8,False)
or
=iferror(hlookup(B$8,transpose(query($A$2:$C$4,"Select C Where toDate(A) < date '" & text(A9, "yyyy-mm-dd") & "' " & " and toDate(B) > date '" & text(A9, "yyyy-mm-dd") & "' ",-1)),1,False)=B$8,False)

Select 'x' returns "x"()

I want to return 3 columns, A(description), 'D'(hard coded value of D), Q(date)
=query('Detailed Plan'!$A$2:$Q, "select A,'D',Q where D = date)
It returns the following results. Rows 2 and greater are exactly what I want and would be perfect if I didn't get the first row. How do I get a hard coded value into a column without "D"() showing up in the first row?
blank, "D"(), blank
Description, D, date
Description, D, date
Description, D, date
Thanks so much for any help that is provided.
You can use 'label' in the query string.
=query('Detailed Plan'!$A$2:$Q, "select A, D, Q where D = date label A 'Description', D 'Some value', Q 'Date' ", 0)
EDIT: if you don't need headers at all, try
=query('Detailed Plan'!$A$2:$Q, "select A, D, Q where D = date ", 0)

Generating JSON response with PostgreSQL for Rails

I'm currently executing a SQL statement in Rails and while it works I've come to realize I need a different format and am attempting to accomplish this in PostreSQL. This is my query:
sql = "SELECT one_month_high - one_month_low as one_month,
three_month_high - three_month_low as three_month,
six_month_high - six_month_low as six_month,
twelve_month_high - twelve_month_low as twelve_month,
ytd_high - ytd_low as ytd,
saved_on
FROM daily_high_lows
ORDER BY saved_on DESC;"
Which returns:
#<PG::Result:0x007fdb4aea1fa0 status=PGRES_TUPLES_OK ntuples=380 nfields=6 cmd_tuples=380>
...
{"one_month"=>"544", "three_month"=>"214", "six_month"=>"9","twelve_month"=>"122",
"ytd"=>"143", "saved_on"=>"2016-06-09 00:00:00"}
{"one_month"=>"1283", "three_month"=>"475", "six_month"=>"22","twelve_month"=>"189",
"ytd"=>"517", "saved_on"=>"2016-06-08 00:00:00"}
I've come to realize that I require a format:
[
{
name: "One Month",
data: {
2016-06-09 00:00:00: 544,
2016-06-08 00:00:00: 1283
}
},
{
name: "Three Month",
data: {
2016-06-09 00:00:00: 214,
2016-06-08 00:00:00: 475
}
}, etc...
]
I've been trying to research how to do this but it's a bit beyond me currently so I could use some direction.
You should be able to use the to_json method available in rails. So response.to_json should yield what you need.
I think if you have a lot of records, building the JSON inside Postgres is a great approach. Postgres didn't really get very useful JSON-building functions until 9.4 though, so I recommend you be at least there if not higher. Anyway, this seems to give you what you want:
WITH seqs AS (
SELECT json_object_agg(saved_on::text, one_month_high ORDER BY saved_on) one_month_highs,
json_object_agg(saved_on::text, one_month_low ORDER BY saved_on) one_month_lows
FROM daily_high_lows
)
SELECT json_agg(j)
FROM (
SELECT json_build_object('name', 'One Month Highs', 'data', one_month_highs)
FROM seqs
UNION ALL
SELECT json_build_object('name', 'One Month Lows', 'data', one_month_lows)
FROM seqs
) x(j)
;
Tested like so:
t=# create table daily_high_lows (one_month_high integer, one_month_low integer, three_month_high integer, three_month_low integer, six_month_high integer, six_month_low integer, twleve_month_high integer, twelve_month_low integer, ytd_high integer, ytd_low integer, saved_on timestamp);
t=# insert into daily_high_lows (one_month_high, one_month_low, three_month_high, three_month_low, saved_on) values (1, 10, 3, 6, '2016-06-08');
t=# insert into daily_high_lows (one_month_high, one_month_low, three_month_high, three_month_low, saved_on) values (2, 9, 3, 8, '2016-03-09');
t=# with seqs as (select json_object_agg(saved_on::text, one_month_high order by saved_on) one_month_highs, json_object_agg(saved_on::text, one_month_low order by saved_on) one_month_lows from daily_high_lows) select json_agg(j) from (select json_build_object('name', 'One Month Highs', 'data', one_month_highs) from seqs union all select json_build_object('name', 'One Month Lows', 'data', one_month_lows) from seqs) x(j);
json_agg
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[{"name" : "One Month Highs", "data" : { "2016-03-09 00:00:00" : 2, "2016-06-08 00:00:00" : 1 }}, {"name" : "One Month Lows", "data" : { "2016-03-09 00:00:00" : 9, "2016-06-08 00:00:00" : 10 }}]
(1 row)

Resources