Ricardo Goncalves Posted May 25, 2015 Report Share Posted May 25, 2015 (edited) Boas, cada vez que executo esta query através deste código retorna o erro "Incorrect Syntax near s" ou seja na primeira quebra de linha da query, alguem me sabe dizer o que estou a fazer mal? Dim sqlCmd As SqlCommand Dim Con As SqlConnection = New SqlConnection("Data Source=127.0.0.1;Initial Catalog=master;User ID=sa;Password=password") Try Con.Open() sqlCmd = New SqlCommand(String.Format("merge datbase1.dbo.PriceLine as T using database2.dbo.PriceLine as S" + "on s.PriceLineID = t.PriceLineID" + "when matched and t.hralt <> s.hralt then" + "Update" + "set t.PriceLineID = s.PriceLineID" + ",t.PriceLineKey=s.PriceLineKey" + ",t.LanguageID=s.LanguageID" + ",t.ShortDescription=s.ShortDescription" + ",t.Description=s.Description" + ",t.WorkstationID=s.WorkstationID" + ",t.SessionID=s.SessionID" + ",t.UserAlt=s.UserAlt" + ",t.DtAlt=s.DtAlt" + ",t.HrAlt=s.HrAlt" + ",t.UID=s.UID" + ",t.ChangeSetID=s.ChangeSetID" + "when not matched by target then" + "insert (PriceLineID" + ",PriceLineKey" + ",LanguageID" + ",ShortDescription" + ",Description" + ",WorkstationID" + ",SessionID" + ",UserAlt" + ",DtAlt" + ",HrAlt" + ",UID" + ",ChangeSetID)" + "values (s.PriceLineID" + ",s.PriceLineKey" + ",s.LanguageID" + ",s.ShortDescription" + ",s.Description" + ",s.WorkstationID" + ",s.SessionID" + ",s.UserAlt" + ",s.DtAlt" + ",s.HrAlt" + ",s.UID" + ",s.ChangeSetID;", Con)) sqlCmd.Connection = Con sqlCmd.ExecuteNonQuery() sqlCmd.Dispose() Con.Close() Catch ex As System.Exception MsgBox(ex.Message) End Try Desde já o meu obrigado a quem responder. Edited May 25, 2015 by Ricardo Goncalves Link to comment Share on other sites More sharing options...
vikcch Posted May 25, 2015 Report Share Posted May 25, 2015 tens que por um underscore "_" no final da linha Link to comment Share on other sites More sharing options...
FDomingos Posted May 25, 2015 Report Share Posted May 25, 2015 Uma das coisas que reparei foi o facto de não estares a dar espaços entre as várias instruções. Por exemplo, nesta instrução: "when matched and t.hralt <> s.hralt then" + "Update" + O que estás a enviar para a base de dados é "when matched and t.hralt <> s.hralt thenUpdate", dá um espaço entre o then e as ". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now