SSIS Expression to get julian date from yesterday - sql

Can anyone help me with SSIS Expression
I have this query in the expression:
Select period, * from table
I want to add a where clause to get period = yesterday
But, period column is in julian date format.
at the end i want the same result like this query
Select period, * from table
Where getdate() - 1
Thank you

you only can use you table date time column to compare with the getdate
Select period,
dataDate, *
from table
Where dataDate = getdate() - 1

Related

select where the date is 1 day before/ after a given date. in base SQL

I don't really have an example but is there a way in the basic SQL to select rows where the date is 1 day before or after a date given by the user?
Yes, if you specify the parameter in the SQL of the query as a date and then perform a numeric comparison:
Parameters [Enter Date] As DateTime;
Select *
From YourTable
Where Abs(Fix([YourDateField])-Fix([Enter Date])) = 1

Extracting data from only the year

I have data in a table in SQL with dates, but how do I select only those that happen in 2021. (The dates look like 31-oct-2020) in the table. The dates are the actual date variable, not just text.
You should avoid storing your dates as text, but rather should use a proper date column. That being said, you may check the right 4 characters of the date string:
SELECT *
FROM yourTable
WHERE RIGHT(date_col, 4) = '2021';
If the column be an actual date type then use:
SELECT *
FROM yourTable
WHERE date_col >= '2021-01-01' AND date_col < '2022-01-01';
I suspect that your DB is Oracle after checking out your previous post. Then you can use
SELECT *
FROM yourTable
WHERE EXTRACT(year FROM dt) = 2021
or
SELECT *
FROM yourTable
WHERE TRUNC(dt,'YYYY') = date'2021-01-01'
or
SELECT *
FROM yourTable
WHERE dt BETWEEN date'2021-01-01' AND date'2021-12-31'
You can benefit the index if there's one on the date column(namely dt) by using the last SELECT statement
If using MSSQL, you can leverage the YEAR(...) to extract the year from a date.
Replace and , with the table name and date column name respectively.
select * from <tablename> where year(<datecolumn>) = 2021

how to query by date in oracle

i have field date like this
type data = varchar
date
2019.01.01
2019.02.02
01.04.2016
i want to get data date >= 2019.01.01
i write query like this select * from mydb date >= '2019.01.01
the results are all data. i want the result just
2019.01.01
2019.02.02
anyone help me ?
If the column is stored as a date:
select t1.date -- use the column name (and if it is called "date", use the table name too)
from t1 -- the table name
where t1.date >= to_date('20190101','YYYYMMDD') -- Oracle dates can be funny
With case to check the format of the date:
select * from mydb
where
case locate('.', date)
when 3 then to_date(date,'DD.MM.YYYY')
else to_date(date,'YYYY.MM.DD')
end >= to_date('2019.01.01','YYYY.MM.DD')
This covers the case where there only exist dates in 2 formats:
DD.MM.YYYY and YYYY.MM.DD

Select records after specific date in SQL

I have a column in my database called "begin_date".
I am trying to select records where the begin_date are greater than a specific date. I put
select * from Table_Name
where begin_date >= '1/1/2014'
However, it returns error message "String to date conversion error".
I am not sure how to modify the query to make it work?
Thanks!
Try using ISO (8601) standard date formats:
select *
from Table_Name
where begin_date >= '2014-01-01';
select *
from table
where data >= '01/01/2014'

Effective date statement where date spans multiple columns

I'm working on a DB2 database and trying to get records by effective date. The only catch is the effective date fields are spanned across 4 columns (month, day, century, year). I think I have the date piece figured out in the select but when I add the where clause I'm having problems. (note that I'm using the digits command to pad because the year 2005 yields just 5 in the year field)
select date(concat(digits(vsmo),concat('/',concat(digits(vsdy),
concat('/',concat(digits(vsct),digits(vsyr))))))) from
ddpincgr d
where (SELECT MAX(<NOT SURE WHAT TO PUT IN HERE>) FROM ddpincgr a WHERE a.vgrno = d.vgrno) <= date('1/1/2000')
Ideas?
Turn it into a sub-query
select *
from (select date(concat(digits(vsmo),concat('/',concat(digits(vsdy),
concat('/',concat(digits(vsct),digits(vsyr))))))) as myDate from
ddpincgr d) as myTable
where max(myTable.myDate) <= date('1/1/2000')
Can't you just put the entire concatenation in the select?
select date(concat(digits(vsmo),concat('/',concat(digits(vsdy), concat('/',concat(digits(vsct),digits(vsyr)))))))
from ddpincgr d
where ( SELECT MAX(date(concat(digits(vsmo),concat('/',concat(digits(vsdy), concat('/',concat(digits(vsct),digits(vsyr))))))))
FROM ddpincgr a
WHERE a.vgrno = d.vgrno) <= date('1/1/2000')