SQL Server to Teradata migration - sql-server

We are migrating from SQL Server to Teradata database. All the views and tables are migrated. But the issue is that we aren't able to take the comments from each table.
In SQL Server we have a function called extended property which if used will get the comments from the respective tables/views. Badhri helped with providing a query for fetching the comment in Teradata in the same way but it doesn’t work in the expected way.
I tried inserting sample comments in columns and the below query is not fetching exact results. Can you please help?
Sample Query:
COMMENT ON COLUMN UtilityApp_DB.SQL_Views_Columns.ColumnNAME 'A Columnname for SQL Server!';
select 'COMMENT ON COLUMN '||trim(b.databasename)||'.'||trim(b.tablename) ||'.'||trim(b.columnname)||' IS '||''''||trim(b.commentstring)||''';'
FROM DBC.Columns b
WHERE b.CommentString IS NOT NULL
AND DatabaseName='UtilityApp_DB'
AND TableName in ('UtilityApp_DB.SQL_Views_Columns');
I created a table and tried inserting the values for the comment string in the table by copying the DBC Columns structure but still I can't get the comment string.
insert into UtilityApp_DB.commentstable (commentstring) values ('UtilityApp_DB.SQL_Views_Columns');

TableName in DBC.Columns does not include the database name and IS in your string concatenation should be AS.
SELECT 'COMMENT ON COLUMN '||trim(b.databasename)||'.'||trim(b.tablename) ||'.'||trim(b.columnname)||' AS '||''''||trim(b.commentstring)||''';'
FROM DBC.Columns
WHERE DatabaseName = 'UtilityApp_DB'
AND TableName IN ('SQL_Views_Columns');

Related

Passing SubQuery into OpenQuery with AS400 Linked Server

I have a Linked Server to the AS400 here. I'm trying to pull data from a field, but it is pulling over a million records when I only need about 20k.
I have a list of IDs that I need, and I'm trying to figure out how to pass that list into the OpenQuery.
Here is my OpenQuery:
SELECT * FROM OPENQUERY(AS400, '
SELECT
IMITNO, IMITD1, IMITD2, IMMFNO, IMBMTP, IMDSCO
FROM AS400.APLUS2FLE.ITMST
WHERE IMDSCO != ''Y''
')
I want to add WHERE IMITNO IN (SELECT item_id FROM as400_item_scope) but the as400_item_scope table is on the SQL machine, not the AS400. I looked at several examples and I can pass in a single variable, but I don't understand how to pass in a list/query like this.
I'm using latest SSMS, but SQL Server Version is 2008
You can't as far as I know...
Two options..
Insert the results of SELECT item_id FROM as400_item_scope into a (temporary?) table on the IBM i and then reference that table in your openquery.
build a comma delimited string with from the results of SELECT item_id FROM as400_item_scope and include that in your openquery string.
Depending on how many records are returned, you might run into issues with statement size trying to use option #2. Db2 for IBM i supports SQL statement of up to 2,097,152 bytes...

ORACLE to MSSQL using SSMS Import Wizard with Query to Update Rows

I have a situation which prevent me of updating rows in a table in MSSQL getting the data from ORACLE. I can INSERT fine from ORACLE to MS SQL using a SELECT statement like:
SELECT XRECORDACTIVATIONDATE, XRECORDCUTOFFDATE, XRECORDREVIEWDATE,
XRECORDFILINGDATE, XNOLATESTREVISIONDATE, XNEWREVISIONDATE, XDATERECEIVEDDOC,
XINACTIVEDATE, DCREATEDATE, DINDATE, DRELEASEDATE, DLASTMODIFIEDDATE
FROM STELLENT.V_EXPORT_TO_MSSQL V
But when I try to update the rows based on an unique ID using:
UPDATE D
SET D.XRECORDACTIVATIONDATE = V.XRECORDACTIVATIONDATE
FROM DBO.DOCUMENT D
INNER JOIN STELLENT."V_EXPORT_TO_MSSQL" V ON D.DID = V.DID
I get the following error:
ORA-00933: SQL command not properly ended
(System.Data.OracleClient)
DBO.DOCUMENT is a MSSQL table.
STELLENT.V_EXPORT_TO_MSSQL is a View in ORACLE
I might be writing wrong the query I will appreciate some help. thank you.
Lukasz is correct - a select statement is a lot different from an insert statement.
The ORA-00933 error means your query is not formed properly. This is because in Oracle, the database expects queries to follow a certain format/standard. Typically, queries within Oracle will have a form of SELECT [columns] FROM [tables] WHERE [conditions]. This can vary - for example if you wanted to select all data from a table, that query might look like "SELECT * FROM [table];" and the WHERE clause can be omitted because you do not need to define a condition for the database to return all rows. While queries can vary in form, in general, they will follow some type of format.
You are receiving this error because your query does not conform to the expected form, and it is because you have an INNER JOIN that directly follows your FROM clause. To fix this, I would recommend creating a query that you use to select the records you want to update, and then using that select statement to form your update statement by replacing the "SELECT" with "UPDATE".
For more on SQL Standards and how to format your queries, I would recommend taking a look at Oracle documentation. https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_1001.htm#SQLRF52344

Powerpivot sql query fails - Unable to convert a value to the data type requested for table column

I'm trying to execute a sql query through powerpivot and I get the following error
"Unable to convert a value to the data type requested for table (massive hex string) column (name)"
SELECT [name], [table].[group],[table2].[group2] ,SUM([number]) AS number
FROM table LEFT JOIN [table2] ON table.[group ID] = [table2].id
GROUP BY [name],[table].[group],[table2].[group2]
Powerpivot's validator is happy with the query and the same query runs fine through sql management studio, any ideas how I can fix this?
this usually happens when you are updating a query in a table that already had data from the original query, and the columns in that table already assigned datatypes based on the previous query.
Either recreate the table or change the datatypes to the ones in your new query.
Hope that helps.
I had same issue. I am querying a Powerpivot book on sharepoint and some of the values coming back were blank or "NaN xxx." This is because I made an Iferror( ,BLANK()) in the measurements.
I changed the calcualted measure from IFERROR( ,Blank()) to IFERROR( ,0) and then I could successfully query the model on sharepoint.

How to merge table from access to SQL Express?

I have one table named "Staff" in access and also have this table(same name) in SQL 2008.
Both table have thousands of records. I want to merge records from the access table to sql table without affecting the existing records in sql. Normally, I just export using OCBC driver and that works fine if that table doesn't exist in sql server. Please advise. Thanks.
A simple append query from the local access table to the linked sql server table should work just fine in this case.
So, just drop in the first (from) table into the query builder. Then change the query type to append, and you are prompted for the append table name.
From that point on, just drop in the columns you want (do not drop in the PK column, as they need not be used nor transferred in this case).
You can also type in the sql directly in the query builder. Either way, you will wind up with something like:
INSERT INTO dbo_custsql
( ADMINID, Amount, Notes, Status )
SELECT ADMINID, Amount, Notes, Status
FROM custsql1;
This may help: http://www.red-gate.com/products/sql-development/sql-compare/
Or you could write a simple program to read from each data set and do the comparison, adding, updating, and deleting, etc.

how to import data from other database in SQL Server 2005

I have 2 databases in SQL Server 2005.
I want a functionality that i have same table structure in 2 database for example i have a same table named as testData in 2 database named as dbTest1 and dbTest2.
Now i want a single query through which i can add all the records from table testData of database dbTest2 into table testData of database dbTest1.
I tried to use following query
insert into dbTest1.testData values select * from dbTest2.testData
but this query is not running and giving error.
I also tried
insert into dbTest1.testData(col1,col2,col3) values select * from dbTest2.testData
but this also gives error that "Invalid object name dbTest2.testData"
Could any one help in this
Thanks
Replace dbTest2.testData with dbTest2..testData - you have to specify 3 things (or optionally leave the middle blank for dbo).
i.e.
insert into dbTest1..testData
select * from dbTest2..testData
If the table doesn't already exist in dbTest1, you can do this:
select *
into dbTest1..testData
from dbTest2..testData
You need to specify all column names in query.
insert into dbTest1.dbo.testData(col1,col2,col3) select * from dbTest2.dbo.testData

Resources