Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Problem with a query - wrong update results Expand / Collapse
Author
Message
Posted Monday, March 4, 2013 1:34 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 22, 2013 2:08 PM
Points: 19, Visits: 63
Hello experts,
I have 2 tables.
One of the tables has the data I need to know which user input it. On the table I have a column name called owner_m, when I run the data import for some reason my sistem is bringing me instead of the user_names the id_user_numbers that is store in tbluser table.
I need to update my data table with the users name and I have the following query for that:

update A
set final_owner=tblUser.tName
FROM A INNER JOIN
tblUser ON cast(A._owner_m as int) = cast(tblUser.aUserID as int)

owner_m is a varchar and User id is an int. Thats why Im using the cast option.

But for some reason the query is giving me the same user id for all the fields as follows:
owner_m tname
19 Carol
20 Carol
28 Carol

instead of
19 Carol
20 Rolando
28 Estefania.

Im asumming is because the data type and I already fix that with the cast function.

I dont know what else to do, please help!!!


Post #1426441
Posted Tuesday, March 5, 2013 7:56 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 6:11 AM
Points: 47, Visits: 134
Change your query to:

SELECT A.final_owner, tblUser.tName, A._owner_m, cast(A._owner_m as int), tblUser.aUserID, cast(tblUser.aUserID as int)
FROM A INNER JOIN
tblUser ON cast(A._owner_m as int) = cast(tblUser.aUserID as int)


And post the results.
Post #1426845
Posted Wednesday, March 6, 2013 11:48 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 22, 2013 2:08 PM
Points: 19, Visits: 63
I got it...thanks a lot!
Post #1427563
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse