Solved

SQl Update Query

Posted on 2013-05-10
1
215 Views
Last Modified: 2013-05-21
Hello,
This update query is not updating correctly
Please assist

If (select count(*) from ROusage where LoginID = @tmpLoginID) = 1
    Begin
            update ROUsage set
            LoginID=q.LoginID,
            ct=q.ct,
            sDate=q.sdate,
            userID=q.userID,
            fName=q.Fname
            from (
            select t.LoginID,t.ct,t2.sdate,u.userID as UserID, u.fName from @tmpTable t
            left join remoteoffice..Users u on u.safeword = t.LoginID
            left join @tmpTable2 t2 on t2.loginid = t.LoginID
            where t.LoginID = @tmpLoginID
            )q
      end
0
Comment
Question by:Mauro Cazabonnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 39156207
In general: Please give guidance on your "This update query is not updating correctly": to much, to few, wrong values,  error,  ....

I guess this is what you need
update R
 set
            R.LoginID=q.LoginID,
            R.ct=q.ct,
            R.sDate=q.sdate,
            R.userID=q.userID,
            R.fName=q.Fname
            from ROUsage as R 
               (
               select t.LoginID,t.ct,t2.sdate,u.userID as UserID, u.fName from @tmpTable t
               left join remoteoffice..Users u on u.safeword = t.LoginID
               left join @tmpTable2 t2 on t2.loginid = t.LoginID
               ) as q ON q.LoginID = R.LoginID
          where R.LoginID = @tmpLoginID

 

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question