Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update statement with Group By

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2010-08-09 : 01:39:25
Hi All,

I am using this query to update the data from another table..

UPDATE users
SET NameGiven = e.NameGiven,
NameFamily = e.NameFamily,
Username = UPPER(RTRIM(SUBSTRING(e.WindowsUserName,4,100))),
Email = e.Email,
CompanyID = '002010'
FROM juice.dbo.emp e
WHERE e.WWID = users.WWID and e.IsActive = 1 and
e.WindowsUserName IS NOT NULL and LEN(e.WindowsUserName) > 3

its throwing an error Pk_Users primary key can't insert duplicate key.

Here Users table is having primary key on Username.
Can we restrict the return data bu using above query.

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-08-09 : 01:50:45
http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/06/30/855.aspx

try the link

With Regards
Kashyap M
Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2010-08-09 : 01:58:55
Not exactly mentioned my problem

Can somebody help me ?
Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-08-09 : 02:57:11
check the InsertCommand in your tableAdapter by right click and choose properties

also make sure the autoIncrement property for the ID column (inside the dataset) is set to false ,and readonly is set to false
try this

With Regards
Kashyap M
Go to Top of Page
   

- Advertisement -