Solved

SQl Update Query

Posted on 2013-05-10
1
197 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:mcazabonnet
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Backup skipping a few tables 7 29
SQL Connection (Error 18456) 14 36
Numeric sequence in SQL 14 38
Error in query 3 0
Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now