Unable to select Variable to set date values in SCD type 2 , SSIS - datetime

I am creating a SCD type 2 dimension. In my destination table there are start time and d]end date columns. I am unable to select the variable to set date values in the SSIS package. Is this something I should configure in the SSIS package? If so, how?

Click on the 'variable to set date values' input box, and use SCROLL THE WHEEL MOUSE to change between variables.

Related

SQLite3 split date while creating index

I'm using a SQLite3 database, and I have a table that looks like this:
The database is quite big and running queries is very slow. I'm trying to speed up the process by indexing some of the columns. One of the columns that I want to index is the QUOTE_DATETIME column.
Problem: I want to index by date (YYYY-MM-DD) only, not by date and time (YYYY-MM-DD HH:MM:SS), which is the data I currently have in QUOTE_DATETIME.
Question: How can I use CREATE INDEX to create an index that uses only dates in the format YYYY-MM-DD? Should I split QUOTE_DATETIME into 2 columns: QUOTE_DATE and QUOTE_TIME? If so, how can I do that? Is there an easier solution?
Thanks for helping! :D
Attempt 1: I tried running CREATE INDEX id ON DATA (date(QUOTE_DATETIME)) but I got the error Error: non-deterministic functions prohibited in index expressions.
Attempt 2: I ran ALTER TABLE data ADD COLUMN QUOTE_DATE TEXT to create a new column to hold the date only. And then INSERT INTO data(QUOTE_DATE) SELECT date(QUOTE_DATETIME) FROM data. The date(QUOTE_DATETIME) should convert the date + time to only date, and the INSERT INTO should add the new values to QUOTE_DATE. However, it doesn't work and I don't know why. The new column ends up not having anything added to it.
Expression indexes must not use functions that might change their return value based on data not mentioned in the function call itself. The date() function is such a function because it might use the current time zone setting.
However, in SQLite 3.20 or later, you can use date() in indexes as long as you are not using any time zone modifiers.
INSERT adds new rows. To modify existing rows, use UPDATE:
UPDATE Data SET Quote_Date = date(Quote_DateTime);

Checking if a Date falls within a Range of Dates in SQLITE

I have an sqlite table with with 2 date columns (beginning & end). I am looking for a query that returns the date range a date falls in. e.g Checking range where 10-02-2016 falls given 2 records as follows
(01-02-2016 - 12-02-2016) & (13-02-2016 - 20-02-2016)
Clearly it falls in the first range but how do I do it in SQLITE. Please help?
I think the problem is next SQLite requires dates to be in format YYYY-MM-DD. With that format you could write a simple query:
select * from table where yourdate between begin and end
If you can't change your format you should look at next sqlite functions https://sqlite.org/lang_datefunc.html
Also you can try substr function to cotact date in needed format.

SQL Server 2012 How to change the data type of a column from bit to datefield?

I have a table Person with a column called onvacation.
This column is of data type bit since it's a boolean in the code. It has values null, 0 and 1.
I would like to change the data type of this column from bit to datetime so that all values that are 1, are converted to a new date (could be current date). and 0 and null values would both be just null.
I tried following w3bschool's tutorial and did a query:
ALTER TABLE Person ALTER COLUMN onvacation datetime
But that gives an error 'DF____Person__onvac__59062A42' is dependent on column 'onvacation'.
you get this error because DF____Person__onvac__59062A42 sql object Depends on onvacation column.
You can Find Dependency of Person table by Right Click-->View Dependancy
remove that dependent object and try to alter column

PostgreSQL, R and timestamps with no time zone

I am reading a big csv (>1GB big for me!). It contains a timestamp field.
I read it (100 rows to start with ) with fread from the excellent data.table package.
ddfr <- fread(input="~/file1.csv",nrows=100, header=T)
Problem 1 (RESOLVED): the timestamp fields (called "ts" and "update"), e.g. "02/12/2014 04:40:00 AM" is converted to string. I convert the fields back to timestamp with lubridate package mdh_hms. Splendid.
ddfr$ts <- data.frame( mdy_hms(ddfr$ts))
Problem 2 (NOT RESOLVED): The timestamp is created with time zone as per POSIXlt.
How do I create in R a timestamp with NO TIME ZONE? is it possible??
Now I use another (new) great package, PivotalR to write the dataframe to PostGreSQL 9.3 using as.db.data.frame. It works as a charm.
x <- as.db.data.frame(ddfr, table.name= "tbl1", conn.id = 1)
Problem 3 (NOT RESOLVED): As the original dataframe timestamp fields had time zones, a table is created with the fields "timestamp with time zone". Ultimately the data needs to be stored in a table with fields configured as "timestamp without time zone".
But in my table in Postgres the data is stored as "2014-02-12 04:40:00.0", where the .0 at the end is the UTC offset. I think I need to have "2014-02-12 04:40:00".
I tried
ALTER TABLE tbl ALTER COLUMN ts type timestamp without time zone;
Then I copied across. While Postgres accepts the ALTER COLUMN command, when I try to copy (using INSERT INTO tbls SELECT ...) I get an error:
"column "ts" is of type timestamp without time zone but expression is of type text
Hint: You will need to rewrite or cast the expression."
Clearly the .0 at the end is not liked (but why then Postgres accepts the ALTER COLUMN? boh!).
I tried to do what the error suggested using CAST in the INSERT INTO query:
INSERT INTO tbl2 SELECT CAST(ts as timestamp without time zone) FROM tbl1
But I get the same error (including the suggestion to use CAST aargh!)
The table directly created by PivotalR (based on the dataframe) has this CREATE script:
CREATE TABLE tbl2
(
businessid integer,
caseno text,
ts timestamp with time zone
)
WITH (
OIDS=FALSE
);
ALTER TABLE tbl1
OWNER TO mydb;
The table I'm inserting into has this CREATE script:
CREATE TABLE tbl1
(
id integer NOT NULL DEFAULT nextval('bus_seq'::regclass),
businessid character varying,
caseno character varying,
ts timestamp without time zone,
updated timestamp without time zone,
CONSTRAINT busid_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE tbl1
OWNER TO postgres;
My apologies for the convoluted explanation, but potentially a solution could be found at any step in the chain, so I preferred to put all my steps in one question. I am sure there has to be a simpler method...
I think you're confused about copying data between tables.
INSERT INTO ... SELECT without a column list expects the columns from source and destination to be the same. It doesn't magically match up columns by name, it'll just assign columns from the SELECT to the INSERT from left to right until it runs out of columns, at which point any remaining cols are assumed to be null. So your query:
INSERT INTO tbl2 SELECT ts FROM tbl1;
isn't doing this:
INSERT INTO tbl2(ts) SELECT ts FROM tbl1;
it's actually picking the first column of tbl2, which is businessid, so it's really attempting to do:
INSERT INTO tbl2(businessid) SELECT ts FROM tbl1;
which is clearly nonsense, and no casting will fix that.
(Your error in the original question doesn't match your tables and queries, so the details might be different as you've clearly made a mistake in mangling/obfuscating your tables or posted a newer version of the tables than the error. The principle remains.)
It's generally a really bad idea to assume your table definitions won't change and column order won't change anyway. So always be explicit about columns. In this case I think your intention might have actually been:
INSERT INTO tbl2(businessid, caseno, ts)
SELECT CAST(businessid AS integer), caseno, ts
FROM tbl1;
Note the cast, because the type of businessid is different between the two tables.

SQL Developer: Load Data Date error

I am using Oracle SQL Developer 3.0.03. I am trying to upload an Excel file to an Oracle data table. I am getting an error for the date. The column in the database is a timestamp and I don't know what to put into the date format for the 'Data Load Wizard'. If I use the following format (dd-mom-yy hh.mi.ss), SQL Developer will show the following error:
--Insert failed for row 1 TIMESTAMP_COLUMN GDK-05047: A day of the month must be between 1 and the last day of the month.
--Row 1
INSERT INTO TABLE_1 (Column1, Column2, Column3, TIMESTAMP_COLUMN) VALUES ('Some Text','Some Text','Some more text',to_timestamp('40604.0', 'dd-mon-yy hh.mi.ss'));
The default number format IN EXCEL is: 40604.0
Which if you change the cell to a short date format you will get: 3/2/2011
I am trying to figure out what 'Format' I need to put into the FORMAT section of the 'DATA Load Wizard' that will accept the date format that is in EXCEL and upload it to Oracle as a TIMESTAMP.
I ran into the same thing today, and 'fixed' this two ways. The second way probably seems too complex, but it might help someone if they have a hard time automating the formatting of dates to look like Oracle's standard dd-mmm-yy.
Format the date columns in Excel as dd-mmm-yy and import directly into the table.
Highlight the column(s)
Choose "More Number Formats" where the existing format is (In Excel 2010, it says General in a dropbox on the Home tab
Select the last entry "Custom" in the Category box
Manually enter dd-mmm-yy in the Type: box
Format the date columns in Excel as mm/dd/yy, import the table in as text, write a manual insert statement from the temp text table using TO_DATE(date_field,'MM/DD/YYYY')
Highlight the column(s)
Choose "More Number Formats" where the existing format is (In Excel 2010, it says General in a dropbox on the Home tab
Select the "Date" entry in the Category box
Choose "03/14/01" from the list
The Excel "zero" date is January 0 (yes, zero), 1900. Since Oracle can't handle a "zero" day in a month you need to subtract 1 from the Excel value; thus the following should get you close to what you want:
SELECT CAST(TO_DATE('01-JAN-1900 00:00:00', 'DD-MON-YYYY HH24:MI:SS') AS TIMESTAMP) +
NUMTODSINTERVAL(41017.6361109954 - 1, 'DAY')
FROM DUAL
As far as "how to import it" goes, there's no Oracle date format that I'm aware of to do this. The easiest thing would be to import the value into a NUMBER column and then run a script to do the date conversion.
Share and enjoy.
yeah and that's the problem.
"A day of the month must be between 1 and the last day of the month."
1) how are these decimals created?
2) is this "04-06-2004" ? or are these seconds from 1970?
you need to add more detail about this number format!

Resources