Skip to content
Advertisement

Transfer Views – ‘value()’ requires a singleton (or empty sequence), found operand of type ‘xdt:untypedAtomic *’

I am trying to transfer views from the AdventureWorks2014 database from one SQL Server to another using Java and JDBC.

In order to obtain the structure of the view, I use the stored procedure “sp_helptext” like this:

ResultSet rs = statement.executeQuery("EXEC sp_helptext '" + view + "';");

where view is the schema and view name (e.g., “dbo.myview”) that I am currently transferring.

When executing the command for the view “Person.vAdditionalContactInfo”, the following structure is returned:

JavaScript

The next step is to execute the retrieved statement on the target database:

JavaScript

For every view in the AdventureWorks2014 db, this worked just fine. But for the “Person.vAdditionalContactInfo” view, the following error is returned after executing the update statement on the target SQL Server:

JavaScript

I’ve looked around the internet for solutions, but haven’t found one. Any help would be greatly appreciated.

Advertisement

Answer

The error that occurred when trying to create the above-mentioned view was caused by a table column the view is referencing.

Before migrating all views of the AdventureWorks2014 database, I used a custom T-SQL script to generate table create statements to migrate tables similarly to the views. A bug in the script caused XML columns to be created as something different from an XML column, which explains why the access to one such column (AdditionalContactInfo of table Person.Person) that was expected to be an XML column was causing this error.

Advertisement