?
Solved

SQl Update Query

Posted on 2013-05-10
1
Medium Priority
?
220 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 1500 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

764 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