Migrate data from one db to another - sql-server

I have two different databases. I have tried using an UPDATE query, but it comes back with an unrecognised error .
How can I reference the DB in the SQL query.
The location is like this for both:
SERVER01\ABC.DB1
And
SERVER01.DB2
EDIT 1:
I have tried
insert into [DB1].[dbo].[table1]
select col1 from [ABC.DB2].[dbo].[table2]
But, I get this error,
Invalid object name 'ABC.DB2.dbo.table2'.

You can specify the database name in the query:
insert into [DbName1].[dbo].[Table1]
select * from [ABC.DB2].[dbo].[Table1]

Related

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

MSSQL - Invalid object name when attempting an update

I have a table in SQL that I can query easily when running SELECT * FROM Scheme.Table1
There are no Intellisense errors and I can see the table in the list of tables under the database
If I attempt to run an UPDATE against the table, I get the error
Msg 208 Invalid object name 'Table1'
Updates against other tabes within the same scheme all work fine
What could be causing this error? Is the wording misleading and it is really something else?
EDIT: update statement is...
UPDATE SCHEMA.TABLE1 SET SCH1 = 'DB', SCH2 = '1' WHERE MEMBERNO = 123999
All fields are correct and exist on the table
Thanks to the comments, it was a trigger on the table that was referencing itself without the SCHEMA (I was logged in using Windows Authentication)

Error after creating the drop down SSRS report parameter

Table structure image atached
I have DataSet already created which has all the fields from the below query.
I am trying to concatenate First and Last Name in a report drop down parameter. I tried creating a calculated field in the DataSet, but dint work.
SELECT DISTINCT
a.DiseId,
n1.LastName,
n1.FirstName,
n1.MiddleName,
...............................
FROM Table1
I also tried creating a separate DataSet by creating the below query -
Select FirstName, lastName, convert(varchar(50),FirstName) + ' ' +
convert(varchar(50),lastName) as FullName from Table2
I can see the Concatenation result in a drop down but I get this below error, this error occured only after I created the new data set with concatenation query.
An error occurred during local report processing.
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
How do I go about to remove the error and create the filter??
Have you tried:
select Distinct FirstName||' '||LastName FullName from table2
Then in your first dataset, use
...where FirstName||' '||LastName = :ParameterName
or if you have multiple selections, do this
...where FirstName||' '||LastName in (:ParameterName)

SQL Server insert or query between servers ingnores column in table starting with a number?

I am trying to query between two servers which have identical tables (used the same create statement for both). When I try to insert the results from Server A to Server B I get an error indicating "Column name or number of supplied values does not match table definition."
Query run on server A
Insert into ServerB.Database1.dbo.Table1
Select *
from Table1
The error is clear, but what isn't clear is the reason that it is generated. The definitions of the two tables are identical. What I was finally able to isolate was a table name that starts with a numeric value is not being recognized.
When I run this on ServerA:
Select *
from ServerB.Database1.dbo.Table1
The field with the numeric value is not shown in the results set of they query. The short term fix was to rename the field in the database, but why is this happening?
I am curious about the collation too, but really the answer is to wrap the object names in square brackets. i.e. SELECT [1col], [2col], [etc] FROM [1database].[2owner].[3table]. This way SQL with recognize each as an object name and not a function.
One other thing to keep in mind is to not use splat (*) in your select statement, this has potential problem of it's own. For example, you could run into an error in your Insert if the ServerA's table1 structure was change and ServerB's table one stayed the same.

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