SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Problem with a query - wrong update results


Problem with a query - wrong update results

Author
Message
montse 22199
montse 22199
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
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!!!
ryan.mcatee
ryan.mcatee
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 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.
montse 22199
montse 22199
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 63
I got it...thanks a lot!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search