How to check each row in a table for at least one null or constant value in SSIS? - ssis

I have a table with 20 fields.
1) Is there any way to check all fields if any of them are NULL?
2) For all columns that are nvarchar i want to search if they contain a constant string value e.g. "Missing".
Can i do the above in SSIS without having to check the columns one by one?

There is no Null-inator that would check if any column is null in a row. However, you could concatenate all the columns in the row and if any column is null then the result will be null. So in a derived column task it could look like this:
Field1 + Field2 + (DT_WSTR, 50)Field3...
As demonstrated in field3, all fields that are not string would need to converted.
Similarly, you can find a keyword, like "missing" by concatenating all the fields in a derived column task and using FINDSTRING(). That could looks like this:
FINDSTRING(Field1 + Field2, "Missing",1)
If the value is greater than 0, you have a hit. There a drawbacks though. Given that your columns are nullable, you would need null handling on all the columns unless this test was only performed on rows where there are no nulls. Also, it doesn't tell you which column has the value, so that probably is not very useful unless you are rejecting or quarantining the entire row.

Related

Query in Access with a "contains" between columns

I need a query in Access with the following:
If Column2, Cell("B1") = "A1" and
Column 1, Cell ("A1")= "B1_A1_DTTROB"
THEN Col3 NEEDS TO SHOW "Contains" or "Correct"
Thanks
As #Minty said - Access understands fields and records. It hasn't got a clue about cells, columns or rows. You can, if you must, think of a field as a column and a record as a row - but you will more than likely get corrected every time you say it out loud.
Saying that, I can see you're trying to compare your first field with the second field on the same record and if it's a match return the text.
SELECT IIF(Column2 = [Column 1],"Contains","Correct") AS Col3
FROM MyTableName
This query will return a table containing a single field called Col3. It will have the same number of records as your original table as it compares the two fields on each record.
To return other fields from your table just add them to the Select clause separated by a comma:
Select Column2, [Column 1], ....
Field names can contain spaces, but you have to wrap the field name in square brackets []. You can also use reserved words in fields, but again wrap them in square brackets [Name].... using spaces or reserved words can causes problems further down the line, so easier to use Column1 rather than [Column 1] and strName rather than Name.
In the field properties in the table design view there is a Caption property that lets you give the field an alias name, but I find this confusing when writing queries in SQL View - Design view will show the correct field name.

mysql colomn value in other column with extra value

In my table in mysql, I have 4 columns, but I added one extra column. And the value of the last column must be the value of column 1 with extra value.
for example:
UPDATE users SET user = 'column_1_value'."00";
It's like merging column value with extra value.
Thanks inadvance !
since you did not provide enough context like the datatypes your table consists of I can just guess. If they are string types (like varchar) you can use concat:
UPDATE users SET column_4 = CONCAT(column_1, "00");

mysql (5.1) > select * from database.table where not foo (on all fields)

I want to select everything in a table where the cell's value is not foo. I thought it would be something similar to WHERE NOT NULL, like SELECT * FROM database.table WHERE NOT 'foo';, but that just returned the column headers with no data.
edit: i want to do this without specifying a particular column (NOT 'foo' for all fields).
There's no way to do this without specifying the fields and conditions, as in
select * from table where
col1 != value and
col2 != value and
...
Depending on what you mean by
the cell's value is not foo
you may need to change and (none of the columns in a row match the condition) to or (at least one column does not match the condition).
As #Jim Garrison answers, you must specify the columns to compare your 'foo' value against. Otherwise you're testing a constant value itself, and that can be either false (zero) or true (nonzero).
SELECT * FROM database.table WHERE NOT 'foo' returns no data because 'foo' is a non-false constant value. Therefore NOT 'foo' is false for every row in the table, and so no rows match and the result is an empty set.
Jim gives one syntax for testing each column in turn. Here's another alternative syntax:
SELECT * FROM database.table WHERE 'foo' NOT IN (column1, column2, column3, ...)
However, I agree with the comment from #Mosty Mostacho. In a relational database, it's weird to test for a single value over many columns. Each column should be a different logical type of attribute, so it's uncommon to look for a similar value among many columns (not impossible, but uncommon).
It usually means you're using repeating groups of columns, which violates First Normal Form. Instead, you may need to create a child table, so that all the values you are searching are in a single column, over multiple rows.
It seems like MySQL is not sophisticated enough to do this. Instead I'll have to add an if-test in my php loop to check for foo and break if foo is present. I didn't want to do this as I have to get down into several nested loops before testing a cell's value…

How to achieve similar datatype

Goal:
Combine two column named first and lastname, from the same table A and then transfer it to column fullname in table B from a another
relational database.
Column first and lastname has the same datatype as fullname. The datatype is varchar(50) or varchar(100).
Problem:
I can't make the transaction to have the same datatype
You need to use the type cast expression DT_STR in Derived Column transformation so that the output from Derived Column transformation is still in varchar data type.
Below shown Derived Column Transformation shows two new columns.
First new column FullName takes in two input columns FirstName and LastName. Concatenates the columns with a space to separate them and then type casts to DT_STR. In (DT_STR, 100, 1252), 100 represents the length of the output column, 1252 represents the code page.
Second new column FullNameNoCast simply concatentates the two input columns FirstName and LastName. This will result in Unicode data type.
Since, you mentioned that your destination is of varchar data type. I believe that you are not type casting the new column in Derived Column transformation. That might lead to the error you are facing.
Hope that helps.

MySQL : multiple column values as 1 comma-separated string?

Suppose I have a select query like :
SELECT * FROM tablename
and in the table are columns : field1, field2 and field3
Does anyone know if it's possible to get a resultset with only 1 row with 1 field, with comma separated values of the columns, like this :
"fieldvalue1, fieldvalue2, fieldvalue3"
Problem is that I don't know the column names of the table in advance...
Another problem is that a prepared statement is not the way to go, since all this should be done from within a trigger, and MySQL doesn't allow dynamic cursors/selects inside a trigger.
I have done some research and only came as far as GROUP_CONCATenating the column names correctly. But the problem is, that
SELECT (SELECT GROUP_CONCAT( cols.column_name) FROM (SELECT column_name FROM information_schema.columns WHERE table_name='test_table') as cols) FROM test_table
will return one and the same concatenated string containing the column names, once for each table row, instead of evaluating it as the column names for the outer select statement and returning the actual values.
From what I have read in all of the forums discussing this kind of question (and there were many), there is really no way of getting this to work without prepared statements.
I can only think of one other way to do this, and that would be having a dedicated column on each table, where you concatenate the individual column values on INSERT or UPDATE, so you can simply select this one field instead of the full set of fields.
Seems like you have 3 questions here:
Getting a resultset with 1 row, 1 field: MYSQL has a CONCAT_WS function that works like this:
SELECT CONCAT_WS(',',Field1,Field2,Field3)
That will return "Field1Value, Field2Value, Field3Value"
I'm not sure how you are going to get these column names. Do you need to get them from a sql statement, a string, etc. ? You can get the table names `SHOW COLUMNS FROM tablename'. The Field column will have the column names.
Triggers are available in mysql (added in 5.0.2 I think): http://dev.mysql.com/doc/refman/5.0/en/triggers.html
First, to find out the columns' names in advance, assuming that you have the table's name, you can get them as any other query:
SHOW COLUMNS FROM your_table
Once you have the names you can do:
SELECT CONCAT(field1,',',field2,',',field3) AS newField FROM your_table