Set the default value of a column based on another column of a different data type - sql-server

I'm creating a new table in SQL table designer, and I'd like the "Default Value or Binding" of the column to be based off the value of another column in the same table. So I'd like Column A to get it's value from a substring of Column B. Column A is a numeric data type, Column B is varchar. Right now I have the following, but get the message in screenshot 2...is there something wrong here? I also had the expression CONVERT(numeric (2,0), SUBSTRING(col_b,3,2)) and that gave the same message.
Screenshot 1:
Screenshot 2:

I don't think you can set the DEFAULT value of one column based on another column using the DEFAULT CONSTRAINT.
You may want to consider a computed column if all you're looking to do is replace a NULL value. http://msdn.microsoft.com/en-us/library/ms188300.aspx
In extreme cases, you can do exactly what you want in a TRIGGER. Read up on INSTEAD OF INSERT triggers. http://technet.microsoft.com/en-us/library/ms175089(v=sql.105).aspx

Related

Alternative to VLookUp that can check if two factors are true

I am wondering is there any alternative to VLookUP() that can check two factors before returning a value. I want to search for an identifier that is only unique for a given date.
I.E the Key exists multiple times in the dataset but only once for each date so the date and the key combined form a primary key.
Note: I want to do this without adding a column to the dataset.
This is a simplified example. I want a formula that will return 304 if I look up using 02/03/20 and 89076.
My current solution is to make another column that concatenates column A and column B and then do a Vlookup on the column but I am looking for a solution that does not require adding another column.
Using Excel 2010
In Excel 2010, if you not looking for a figure but actual text, try the following:
=INDEX(D:D,MATCH(1,INDEX((A:A=DATEVALUE("02/03/20"))*(B:B=89076),),0))

Multiple column names in PutHBaseRecord Row Identifier Field Name property in NiFi

I have a simple flow of extracting rows from Oracle Table and putting it into Hbase via NiFi.
To Extract Data from DB I am using "QueryDataBase Table" and put to HBase I am using "PutHbase Record" Processor.
Usually, whatever is the primary key of my Table I am using it as a "Row Identifier Field" in putHbaseRecord.
My problem is arising when there is Composite Primary Key, As Row Identifier Field property in putHbase Record processor is not taking multiple columns.
Any help in this will be really Helpful.
Thanks
Unfortunately this is not currently possible with PutHBaseRecord. It would require a code change to the processor to allow the specifying multiple field names for the row id, and then it would have to get them and from each record and concatenate them together to form the row id value.
It might be better to make the property be a record path expression that creates the row id. This way if you want a single value you just put something like '/field1' and if you wanted a composite value you'd do something like "concat('/field1', '/field2')".

Oracle 12c - column default string value for record not inserted - null instead

I am facing the very interesting intermitted issue and I don't know what can cause this issue. I have one database table and there is set DEFAULT value for one column (string value - i.e. "A").
Records are inserted automatically with scheduler job and I looked at the history and once there was inserted "null" instead of "A" value - only for one record. Other records were inserted correctly.
(note: there were thousands of records inserted and only one had null)
Do anybody know what can cause this intermittent issue and why there is null instead of DEFAULT value which is defined for this particular column?
If you need some example of the table definition, let me know.
Thank you
DEFAULT values are only used when a column is not referenced in an insert statement. If a column is referenced and is nullable then it can be set to null.
With 12c you have the option to change this behavior by using DEFAULT ON NULL instead of just DEFAULT.
Reference: DEFAULT Values On Explicit NULLs

How to modify field in ecto by Algorithm

Hello everyone i'am looking for method to change field types and convert its values during this.
I mean something like that:
def up do
alter table(:users) do
modify :role, :integer, default: fragment("convertion_function")
end
end
I know Ecto.Migration#modify/3 function gets &fragment/1 argument. But it gets only one argument.
Does anyone know if it possible to pass current value to &fragment/1 function?
Or maybe anyone know better way to do that?
In PostgreSQL, this can be done by specifying a USING clause to the ALTER TABLE <table> ALTER COLUMN <column> query. I couldn't find any support for this in Ecto's migration. You can use execute to execute a raw query to do this. Here's how you'd alter the posts table's title column from a string to integer and set the new value to be the length of the original titles:
def up do
execute """
alter table posts
alter column title
type integer
using length(title);
"""
end
length(title) being the fragment expression which calculates the new value.
You'll want to write a similar query for the reverse migration as well.
You can read more about USING in ALTER TABLE here.
default would set the default value for new rows, it has nothing to do with the conversion of existing data.
AFAIK, there is no way to modify the column type without losing the data in PostgreSQL/MySQL. The only way would be to create a new column with migration #1, migrate existing data there with migration #2 and remove old column + rename the new column to the old name with migration #3.

OBIEE Characteristic Table with dynamic header

I have original data as shown above with a single record. I have name of the field in one column and value in another column. I need to transform make the heading dynamic as shown below.
I tried with table pivot table and trellis, not no success.
You should be able to do this in a pivot table in OBIEE.
Please see my below screenshot. I was able to get my column originally named 'Total Contracted Cases' to now be called 'USD' because that is the value in the column 'Currency Code'. So for you, you should be able to get the column 'PARAM_VAL1' to be called 'COUNTRY' because that is the value in the column 'PARAM_CD1'. See below for my example:
In the second image, be sure to click on the 'Measure Lables' properties to hide the value.
For columns that are not metrics (no aggregation rule set) that will be used in the 'Measures' section of the pivot table, you will have to define an aggregation rule in the column properties dialog box to keep the value from being converted to null. If your data is as you say it is (a single record), then this should not be an issue; you should be able to pick any aggregation rule and not have to worry about dropping data.

Resources