How to convert ADF Pipeline Run Id (string) to GUID? - azure-sql-database

I have a table in a SQL database with a UNIQUEIDENTIFIER data type
I would like to populate this table with the Pipeline Run Id parameter in Azure Data Factory
When I pass this parameter, it is passed as a string value, my table in the SQL database expects a value GUID() value. Is there a way to convert the parameter to GUID() type. Or should I consider changing the datatype in the target table?
Thanks in advance :)

You'll probably be better served by changing the SQL data type to a varchar if that's possible. Pipelines don't have a variable type for guid. They also do not have a conversion function for string to guid. The guid() function generates a new guid value but returns a string. The Data Flow expression language doesn't even contain a reference to guid. All in all, my conclusion is if you can just treat them as strings you should.

Related

SQL data types for AnyLogic

I am saving the output of my AnyLogic model into an SQL server database. For non-AnyLogic aficionados, AnyLogic is based on Java. However, I am not sure what data types I need to specify for my columns in the database.
So far I am using these:
double in AnyLogic : float in SQL
string in AnyLogic : varchar in SQL
int in AnyLogic : int in SQL
I also have parameters that are of type Option list, which is, if I understand correctly, a form of Java enum. I tried to save those parameters as varchar, but this (obviously) does not work. In addition, my model contains various boolean parameters. For my boolean parameters, I add columns of type bit in SQL by running:
ALTER TABLE myTable
ADD my_bool BIT NOT NULL DEFAULT 0;
However, running the model returns this error
SQLServerException: Invalid column name 'false'. Caused by: Invalid column name 'false'
So concretely, how can I export parameters of type Option list and boolean?
This addresses the original question which was tagged MySQL.
I don't know all the issues around "option list". Seems like a string (with a length such as varchar(255)) would work. You can also look into the built-in enum type, although I would not normally recommend using enums.
I would recommend using boolean instead of bit as the equivalent for boolean. Seems more mnemonic.
That said, MySQL understands false as a constant. You can check this by running:
select false
This also works:
select "false"
However, this returns the error that you specify:
select `false`
I suspect that the code being generated is using this construct. You will need to look at the code -- and you might need to figure out some other way of handling this. In MySQL you can use 0 for false and that might fix your problem.
The AnyLogic database is a standard HSQLDB database (not something proprietary) but they've added AnyLogic client functionality to define 'column types' as though they are Java types (with special types for option lists and compiled-on-the-fly-and-run Java code).
If you look at the db.script file (HSQLDB just stores the persistent DB data as an SQL script which creates the tables and INSERTs the values) you can see the underlying HSQLDB types which map closely to SQL Server types.
boolean --> BOOLEAN
double --> DOUBLE
int --> INT
String --> VARCHAR(16777216)
Date --> TIMESTAMP
Code --> VARCHAR(16777216)
Option List --> VARCHAR(255)
NB: The 'Java column types' are supposed to make it easier for a non-technical user to understand what they will get from a Java perspective when querying that column but, for example, they are confusing in that queries will return Java nulls for missing values, so a boolean column actually effectively returns a Boolean.
That should help.
I managed to address part of my problem. I am now able to store String variables from Java into my SQL database. The issue was due to incorrect use of quotations.
Java uses double quotations for String variables (e.g.: ""). SQL expects single quotations (e.g.: '') for string-like columns such as varchar() and char()
I had to amend my SQL query to this:
String insertTableSQL = "INSERT INTO test (my_string) VALUES(" +" '"+my_variable_string+"' )";
Note that my_variable_string is a derivative of a Java enum, which I obtained by executing String my_variable_string= my_enum.name();

Replacing Null Values Using Derived Column in SSIS

I have a data flow task which picks up data from a non-unicode flat file to a SQL Server table destination.
I'm using a Derived Column task to replace NULL values in a date column with the string "1900-01-01". The destination table column is a varchar data type.
I'm using this SSIS Expression (DT_STR,10,1252)REPLACENULL(dateColumn,"1900-01-01") and the task executes successfully but I still see NULLs instead of the "1900-01-01" string at the destination.
Why is this? I've tried replacing the column, adding a new column but whatever I do I still see NULLs and not the replacement string. I can see my new derived column in the Advanced Editor so can see no reason why this isn't working. Any help would be most welcome.
If your your source is non-unicode, why are you using DT_STR? varchar is a already a non-unicode data-type. You should just be able to do it with
REPLACENULL(dateColumn,"1900-01-01")
Also, did you put in a lookup transformation to update the column? Have you made sure the right keys are being looked up and updated?

Conditionally changing a variable data type based on input

We have a stored procedure that gets call from an application. One of the input to the SP is SSN. We are using SQL Server 2008R2 Enterprise Edition.
The SSN data type is input as VARCHAR(9). We take that SSN and join it to a table who has the SSN stored as DECIMAL(9,0). This causes an implicit conversion at execution time and is affecting performance.
My original plan was to have the input come in as VARCHAR and just copy the variable over to another variable with the DECIMAL datatype however, we have a kink in the process. A user can also input text as 'new' when there is a new client. When this happens, we get a failed to convert datatype varchar to decimal.
Is there a way to conditionally change the data type of a variable based on the input it receives?
Here's an example of what I am trying to use now, to no avail, as the instances where 'new' is entered cause a conversion error:
CREATE PROCEDURE [dbo].[StoredProcedureFromApplication](
#SubscriberSSN VARCHAR(9))
AS
DECLARE #SSN_DEC DECIMAL(9,0)
SET #SSN_DEC = #SubscriberSSN
Any ideas on how to have the datatype able to be changed?
First, you should store SSNs as strings and not numbers, because they can start with 0.
I think the best you can do is to have the resulting value be NULL
SET #SSN_DEC = (case when isnumeric(#SubscriberSSN) = 1
then cast(#SubscriberSSN as decimal(9, 0))
end);

SSIS ForEach Variable Mapping Error

I want to be able to send emails using SSIS. I followed the instructions at "How to send the records from a table in an e-mail body using SSIS package?". However, I am getting an error:
Error: ForEach Variable Mapping number 1 to variable "User::XY" cannot be applied
while running the package. My source table has 5 columns (bigint, datetime, nvarchar, nvarchar, nvarchar types).
Another error is:
Error: The type of the value being assigned to variable "User::XY" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
What could the problem be?
UPDATE: As I was trying to find out the problem, I have done this: while taking the data from Execute SQL Task, I cast the int data to varchar and then use the variable with String data type and it works. But how should I set the variable so it has INT data type, not varchar?
I just ran into this problem & resolved it, although I don't know exactly how.
Running SSIS for SQL Server 2008 R2:
a) query pulls rows into an object
b) for each trying to loop through and pull values for the first two columns into variables
(this had already been running fine--I had come back to edit the query and the for each loop and add an additional variable for branching logic)
c) error mapping variable '1', which happened to be an int and happened to have the same name as the column I was pulling from.
I tried deleting the variable-to-column reference in the foreach loop and re-adding it, and I discovered that the variable was not listed anymore in the list of variables allowed for mapping.
I deleted the variables, created a new variable of the same type (int32) and name, added it, and things ran fine.

How to insert an existing GUID into Oracle RAW(16) field in a script

I have an sql server script which inserts known fixed guid values into a table. It looks like:
INSERT INTO MyTable (ID)
VALUES ('BBD098BF-58F0-4A84-90C2-F806D6D06061')
Note that guid is in human-readable form.
Since ID is uniqueidentifier sql server understands how to convert a string to guid data type.
I need to make the same script for Oracle, ID is of RAW(16) type. Taking the script directly doesn't work because Oracle interprets a string just like a binary, it should be some "other" string, a string representation of a correct binary chunk.
Does anyone knows a way to convert human-readable sql server string to a string required by Oracle?
So far I can only think about saving a guid to Oracle in .net code, for example, and than making a select in oracle script to get a string. But this is crazy.
Thanks!
According to this link
Sqlserver reverses the 3 first sections so you need to do:
hextoraw(substr(guid,7,2)||
substr(guid,5,2)||
substr(guid,3,2)||
substr(guid,1,2)||
substr(guid,12,2)||
substr(guid,10,2)||
substr(guid,17,2)||
substr(guid,15,2)||
substr(guid,20,4)||
substr(guid,25,12)
)
(guid is like 'BBD098BF-58F0-4A84-90C2-F806D6D06061')