-1
Update details 
  set details.a=a, details.b=b 
where Id=10 select a,b from @userdefinedtabletype

Here id is unique for all the records

  • Which [DBMS](https://en.wikipedia.org/wiki/DBMS) product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a [tag](https://stackoverflow.com/help/tagging) for the database product you are using `postgresql`, `oracle`, `sql-server`, `db2`, ... –  Nov 13 '18 at 11:31
  • You must explain more if do you want to solve your problem – yusuf hayırsever Nov 13 '18 at 11:39
  • I am updating the datatable using unique or reference id in ms SQL usind user defined table type – Devaraneni Laxman Rao Nov 13 '18 at 12:02

1 Answers1

0

Since you have not provided much detail as to what either table has in it I am going to assume that your user defined table only has one row in it. Otherwise you will get the last values that are returned from the query.

So I would use a CROSS APPLY to do the update such as:

Update details 
  set details.a=t2.a, details.b=t2.b 
from details t1
CROSS APPLY (select a,b from @userdefinedtabletype) t2
where t1.Id=10 

If in fact these tables are related by an ID of some sort then you would probably want to do an INNER JOIN:

Update details 
  set details.a=t2.a, details.b=t2.b 
from details t1
INNER JOIN @userdefinedtabletype t2 on t1.id = t2.id
where t1.Id=10 
JMabee
  • 2,230
  • 2
  • 9
  • 13
  • Actually my requirement is I inserted the two table s using datatable and using first table identity column is inserted into the second column id ( this id is same for all records) in that am using user defined table type for inserting the data at a time and also updating the second table some columns based on the id using the user defined table type ,but it's not working which I mentioned above query – Devaraneni Laxman Rao Nov 13 '18 at 17:53