SQLTeam.com | Weblogs | Forums

Update Query Does Not Work

Using VS Express 2013 - I have an update query that when run gives the "Incorrect syntax near 'nvarchar' error. No one seems to be able to figure it out. So, I began scaling down the query by removing fields. I got down to one field and still got the error. Does this indicate a permissions issue or something else?

Thank you.

show us the code. and are you using functions?

UPDATE tblDimPatients SET FullName = FirstName + ' ' + MInitial + ' ' + LastName, FirstName = FirstName, MInitial = MInitial, LastName = LastName, Suffix = Suffix, Address1 = Address1, Address2 = Address2, City = City, State = State, ZipCode = ZipCode, County = County, PhoneHome = PhoneHome, PhoneWork = PhoneWork, PhoneCell = PhoneCell, Fax = Fax, Email = Email, DOB = DOB, Gender = Gender, VocEdCoordinatorID = VocEdCoordinatorID, GraduatingYear = GraduatingYear, Comments = Comments, Status = Status, HomeSchool = HomeSchool, CurrentSchool = CurrentSchool, MedicalRecordNumber = MedicalRecordNumber WHERE (PatientID = @HoldPatientID)

I created this DDL to vet out your code and I do not see any issues with the above code you provided.
The issue seems to be elsewhere . And your code is doing an update of a table row with the same values of the table row, why? Is this some sort of learning you are doing?

use sqlteam
go

declare @HoldPatientID int = 999;

create table #tblDimPatients(PatientID int , 
FullName nvarchar(50), 
FirstName nvarchar(50), 
MInitial nvarchar(50), 
LastName  nvarchar(50), 
Suffix int,
Address1 nvarchar(50), 
Address2 nvarchar(50), 
City nvarchar(50), 
State nvarchar(50), 
ZipCode nvarchar(50), 
County nvarchar(50), 
PhoneHome nvarchar(50), 
PhoneWork nvarchar(50), 
PhoneCell nvarchar(50), 
Fax nvarchar(50), 
Email nvarchar(50), 
DOB nvarchar(50), 
Gender nvarchar(50), 
VocEdCoordinatorID  nvarchar(50), 
GraduatingYear nvarchar(50), 
Comments nvarchar(50), 
Status nvarchar(50),  
HomeSchool nvarchar(50), 
CurrentSchool nvarchar(50), 
MedicalRecordNumber nvarchar(50))


UPDATE #tblDimPatients 
   SET FullName = FirstName + ' ' + MInitial + ' ' + LastName, 
       FirstName = FirstName, 
	   MInitial = MInitial, 
	   LastName = LastName, 
	   Suffix = Suffix, 
	   Address1 = Address1, 
	   Address2 = Address2, 
	   City = City, 
	   State = State, 
	   ZipCode = ZipCode, 
	   County = County, 
	   PhoneHome = PhoneHome, 
	   PhoneWork = PhoneWork, 
	   PhoneCell = PhoneCell, 
	   Fax = Fax, 
	   Email = Email, 
	   DOB = DOB, 
	   Gender = Gender, 
	   VocEdCoordinatorID = VocEdCoordinatorID, 
	   GraduatingYear = GraduatingYear, 
	   Comments = Comments, 
	   Status = Status, 
	   HomeSchool = HomeSchool, 
	   CurrentSchool = CurrentSchool, 
	   MedicalRecordNumber = MedicalRecordNumber 
WHERE (PatientID = @HoldPatientID)

drop table #tblDimPatients

Yes, I am just learning. Someone helped me set this up last year and I tried to pick it back up. He left the company and three other people could find nothing wrong with the query. What else do you think it might be?

Thank you.

I think you are showing us only one piece of your pain point

What else is there in the environment you are running. Until you provide other pertinent details its just shot in the dark .

It's like trying to diagnose a disease over txt messaging

Hi

Please forgive me. ..if i am offending..
Sorry this might be another topic
Write down on a piece of paper ..all possible things you can think of ..
Eliminate one by one
Example ..

  1. syntax issue
  2. data issue
  3. spelling mistake
  4. was working before not now
    Etc etc ...

I googled
Tsql update incorrect syntax near nvarchar

Please check this link
Could be your issue
https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.sqlteam.com/forums/topic.asp%3FTOPIC_ID%3D58195&ved=2ahUKEwjy2-aejqbkAhVKKY8KHY3IDVgQFjAEegQIAxAB&usg=AOvVaw12a0tagsFV_jB7JcbS4NVm

its also possible

the error is some where else in the script

and it points to your update statement !!!!

:slight_smile: :slight_smile: