bernie2436
bernie2436

Reputation: 23901

strange syntax error in t-sql

I am trying to write a query that deletes records from one table and outputs the deleted records into another similar (but not identical) table.

This code is what I am trying to do:

delete from MyServer.dbo.t1
output deleted.colA into MyServer.dbo.t2.colA

It raises the error, could not find server 'MyServer' in sys.servers.

However, I am able to run this (basically no-op) code (using a valid server name):

delete from MyServer.dbo.t1
output deleted.* into MyServer.dbo.t1

So basically t-sql's error message does not seem to make sense--so I am not sure what to do.

  1. why is t-sql throwing this weird error? why can it "see" MyServer in sys.servers sometimes but not other time?

  2. what is the correct syntax for outputting deleted values for particular columns into new tables

Upvotes: 1

Views: 98

Answers (1)

cjk
cjk

Reputation: 46425

When you use 3 . in your syntax, you are specifying server.database.schema.table. You are trying to add column on the end which does not work. Get rid of the .colA.

Upvotes: 1

Related Questions