Create Null-able numeric column in Derived column component - sql-server

I use SSIS in SQL Server 2016. I have to create a new column in my DataFlow. I use DrivedColumn component to create this new column. In this case I need a nullable numeric column like below image :
As you can see, I have error in this case.
How can I create null-able numeric in Derived column component?

In the derived column task there are NULL Functions that you can use if you would like to set a value to NULL.
Select the appropriate NULL function that corresponds to the datatype of your column and plug that into your equation.
You can use NULL(DT_CY) if your column is defined as currency.
Example. ([currencyAmount]>0? [currencyAmount]:NULL(DT_CY)
In the Derived Column task Null Functions can be found here:

Related

Clickhouse - add a new column with the default value being based off another column

I have a table in Clickhouse, table1, with columns A and B. I want to alter this table to have a new column C. For the purpose of default values (future data will have a different approach) I want C to be filled in with data from A.
I know how to achieve this with a static default value, e.g. 0 but that is not what I'm trying to achieve here.
DEFAULT may accept expression not only static value:
ALTER TABLE table1 ADD COLUMN C String DEFAULT A

Execute a function for a column value every time a record is created in a table

I am running code that creates a record on a table in SQL Server 2014. The record is coming from my PHP backend that has an insert statement with new values. The table contains a 'reference_number' column that is supposed to be a concatenation of the first two letters of the 'type' column and an incrementing 7 digit number.
Now I could have done this easily playing with the column properties if it was just an incrementing integer value. So is there a way in SQL Server 2014 using functions or stored procedures (etc...) to give the column a generated value every time a new record is created?
For example I can use the built-in getDate() function every time I need to fill a datetime valued column. So can I write a function similar that accepts a parameter as the column value I am providing in the insert statement for the 'type' column and let the code do the rest? How?
Notes:
I am new to SQL server, although I know and have a background on the basics of databases in general.
Writing the code in PHP isn't a choice as its a specifically expected requirement I have to achieve.
Would love to hear new approaches/examples or recommendations on how to solve this.
Thanks so much!
you need an Identity column
alter table myTable add column Sequencenumber
int identity (1000000, 1) not null
^ ^
Start at this value | |
| //increment by this every time
Your reference number can then be a computed column using the Identity column and your Type column.
for example
alter table myTable add
Reference_number as
left(type,2) + cast(Sequencenumber as varchar(10))
See the documentation here Identity, and computed columns here computed columns

nullable column with Postgres API

With libfq and the C API, is there a way to get the nullable metadata of a column from a query?
I'm just talking about the property of a column, not the NULL value from a resultset.
For instance, with MySQL:
mysql_fetch_field_direct()
does the job.
I tried with PQfmod, but without success.
Information about the table definition is not part of the result set data.
You can find out if the value is NULL, but not if the column is nullable or not.
A column in a result set need not be related to a certain column in a table!
To get information about a column's definition, query information_schema.columns. The is_nullable column will contain the information.

SQL Server Table Partition Data Type

I have a table with over 70 million rows which I want to partition using the date/time column, however the date/time column has varchar datatype instead of date.
What is the best way of converting the datatype dynamically to be able to use the column as a partition range ?
Thanks
I suggest you add a new PERSISTED COMPUTED column and then create partition on the computed field.
The computed column should be type of date and it is simply conversion of your varchar column.
I have done this before as experiment and it works.

SQL Server - How to remove IsPersisted attribute on computed column

In SQL Server, how can we switch off the PERSISTED attribute of a computed column using T-SQL? I am able to do this using Management Studio GUI but do not know how to do it using T-SQL.
If you want to drop the PERSISTED property from your column, then you can try the following:
ALTER TABLE dbo.MyTable ALTER COLUMN MyColumn DROP PERSISTED;
According to MSDN:
[ {ADD | DROP} PERSISTED ]
Specifies that the PERSISTED property is added to or dropped
from the specified column. The column must be a computed column that is
defined with a deterministic expression.
Related: You can also have a look at this article by Aaron Bertrand.
You can do this by following this steps:
Create a new column in your table having the same datatype as that of your persisted column.
Update the new column with the persisted column value.
Remove the persisted column from your table.
Rename the new column as that of the persisted column.

Resources