Insert to and select from - tsql

I am preparing Microsoft SSIS Certification. In the exercice Practice_5-Loading Data: the code provided by the training kit Exam 70-463 doesn't work.
Error message:
Msg 121, Level 15, State 1, Line 3 The select list for the INSERT
statement contains more items than the insert list. The number of
SELECT values must match the number of INSERT columns.
Error message:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'GO'.
Need some help.

Concatinate the two columns (C.FirstName, C.LastName) as fullname.
Thanks
Sasi

I finally find the problem. they were different structure between tables I created and the loading from table... primary key was different and 'curent flag' data type need to have default value set to 1.
thanks for your help
sagbo

Related

PutDatabaseRecord failed with Index header CSVRecord

We are trying to insert data to postgresql based database.
We use PutDatabaseRecord processor with following configurations :
But we get an warning and data is not inserted to database and records are not inserted.
Is this apache commoncsv related issue?
How can I solve this issue?
Edit :
After #matt's initial answer : I found intersting thing with data, in address field it has :
"No 60, Marine Drive,"
CSVReader in PutDatabaseRecord uses , value separator. So address must be read as 3 different column values.
The error seems to indicate you have more columns in the header than in (some lines of) data. If that's not the case, I suspect there's either a bug when handling empty columns, or Infer Schema doesn't work as expected with an empty column in the first row (how would it be able to guess the type of "nothing"?).

Update statement gives error with some IDs and not others

Have a database that I restored from a backup on a new sandbox server. I ran a very innocuous update statement:
UPDATE insurance
SET plan_text='MS MEDICAID'
WHERE insurance_id=168331
I received the following error:
Msg 4121, Level 16, State 1, Procedure insurance_track_rev_type1, Line
70 [Batch Start Line 0] Cannot find either column "master" or the
user-defined function or aggregate "master.dbo.GetHashGuid", or the
name is ambiguous.
I changed the ID, the new statement is as follows:
UPDATE insurance
SET plan_text='MS MEDICAID'
WHERE insurance_id=168334
I received the following:
(1 row affected)
I have no idea what is going on. Any ideas?
JG

Select/Insert from identical table on two different DB connections

I have to do a select from a table and insert into another identical(same structure) table on two different DB connections.
This is my code:
from("direct:" + getId)
.toD("sql:classpath:" +getSql1 + "?datasource= DataSourse1&usePlaceHolder=true"))
.setHeaders("Results", simple(${body})
toD("sql:classpath:" +getSql2 + "?datasource= DataSourse2&usePlaceHolder=true"))
where
getSQL1 : Select * FROM Product1
and
getSQL2 :Insert Into Product2 Values(${headers.results})
It does not work because of the data format I'm trying to insert, I suppose. What I get from the Select is something like this:
[{ID=130, DESCRIPTION=Product130}]
So, I need to clean my data and get only 130, 'Product130'
Any help? Thanks.
Assuming your actual code works and you're just transferring one record, change the getSql1 select option part to this:
"?datasource= DataSourse1&usePlaceHolder=true&outputType=SelectOne"
That puts a map into your message body as a result, instead of List of Map. No need to copy the result into a header. With Camel's SQL component, it will look for named query parameters in your message body if the body type is a Java Map.
Next change your insert to use the parameters within the Map:
insert into Product2 (ID, DESCRIPTION) values (:#ID, :#DESCRIPTION)
Notice I included the column names. This is for safety and good practice. If by chance the column order isn't the same as the origin table, this will still work.

split a field in redshift

I have a my table in redshift that contains some concatenated id
Product_id , options_id
1, 2
5, 5;9;7
52, 4;5;8,11
I want to split every my table like this:
Product_id , options_id
1 , 2
5, 5
5, 9
5, 7
52, 4
52, 5
52, 9
in the documentation of redshift, i find a similar function 'split part' but with this function i must enter the number of the part that i want to get exp:
Product_id , options_id
5, 5;9;7
split_part(options_id,';',2) will return 9,
Any help please
Thanks.
So, the problem here is to take one row and split it into multiple rows. That's not too hard in PostgreSQL -- you could use the unnest() function.
However, Amazon Redshift does not implement every function available in PostgreSQL, and unnest() is unsupported.
While it is possible to write a User Defined Function in Redshift, the function can only return one value, not several rows.
A good option is to iterate through each part, extracting each in turn as a row. See the workaround in Error while using regexp_split_to_table (Amazon Redshift) for a clever implementation (but still something of a hack). This is a similar concept to Expanding JSON arrays to rows with SQL on RedShift.
The bottom line is that you can come up with some hacks that will work to a limited degree, but the best option is to clean the data before loading it into Amazon Redshift. At the moment, Redshift is optimized for extremely fast querying over massive amounts of data, but it is not fully-featured in terms of data manipulation. That will probably change in future (just like User Defined functions were not originally available) but for now we have to work within its current functionality.
Stealing from this answer Split column into multiple rows in Postgres
select product_id, p.option
from product_options po,
unnest(string_to_array(po.options_id, ';')) p(option)
sqlfiddle

IBM DB2 SQLException with "DB2 SQL Error: SQLCODE=-420, SQLSTATE=22018, SQLERRMC=DECFLOAT, DRIVER=3.66.46"

I am working on a Jasper report using iReport 5.6 and IBM DB2 as data source. I am passing a list of strings as a parameter to the report and that is where the problem rises. The query is below;
SELECT customers.mobile_number,
COALESCE(Count(DISTINCT transaction_entries.transaction_id), 0) AS
number_of_transactions,
COALESCE(Sum(Abs(transaction_entries.amount)) / 100, 0) AS
volume_of_transactions
FROM transaction_entries
JOIN customers
ON customers.id = transaction_entries.customer_id
WHERE transaction_entries.transaction_type = 'Seasonal'
AND transaction_entries.notification_text <> 'Notification'
AND customers.mobile_number IN ( $p ! {listOfMobileNumbers} )
GROUP BY customers.mobile_number
When I try to generate the report I get the error Caused by: com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-420, SQLSTATE=22018, SQLERRMC=DECFLOAT, DRIVER=3.66.46.
Any idea why ? and the possible solution ?
I would first verify that by commenting-out the last predicate of the WHERE clause avoids the error; i.e. redact the failing statement such that the IN predicate referencing the Jasper variable as input is no longer part of the query.
Then, determine what defines that variable replacement, from the output of the following query:
select '$p ! {listOfMobileNumbers}' from sysibm.sysdummy1
If the effect of the above query, used to reveal the data in that list, presents something like '1234,567,890', then I would suggest modifying the data that defines that list to reflect either of '1234','567','890' or 1234, 567, 890 instead.
FWiW: IMO the actual DDL [for column(s) or the TABLE] is much clearer to a reader than suggesting merely that:
The mobile_number field is returned from the database as a String and not a DECIMAL