Solved

SQl Update Query

Posted on 2013-05-10
1
203 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL: Subtracting Amounts from "Among Rows" 3 43
TSQL previous 5 25
Help Extract Specific in SQL 8 25
sql query questions 2 25
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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 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

16 Experts available now in Live!

Get 1:1 Help Now