Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updateing 2 columns at the same time

Author  Topic 

Sambhav
Starting Member

31 Posts

Posted - 2007-07-03 : 11:43:51
Hi please help me out !!
I have to update the incidents table.
The initiator and initdept are two corresponding columns in incidents table whoes value I have to get from another table Employee where (initiator means Empname and initdept means title)
if i just do

select Empname,title from employee

it gives me correct output while

select initiator,initdept from incidents

It gives the initiator correct but instead of giving the initdept
it gives output as initaiator
The Output is given below

initiator initdept
Jeff C. Taylor Jeff C. Taylor
Randy S. Jonas Randy S. Jonas
Mike lewis Mike lewis

it should give the out put like

initiator initdept
Jeff C. Taylor Software Engg
Randy S. Jonas Tester

I hope you got my question!
now I hav to update incidents table such that it should give initiator as well as its corrosponding initdept

thanks





harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-07-03 : 12:00:20
Do you really want to Update incidents table? or just want to display initiator and corresponding department in SELECT statement?

Select e.EmpName as Initiator, e.Title as InitDept
From Employee e JOIN incidents i on e.pk = i.pk


Note: pk indicates key column which is common in both tables, most probably primary key.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Sambhav
Starting Member

31 Posts

Posted - 2007-07-03 : 12:35:33
I have to update it as I am populating data for testing
and the primary key what I think is Empname only because the common field are title and empname ....

sambhav jain
Go to Top of Page

Sambhav
Starting Member

31 Posts

Posted - 2007-07-03 : 15:03:27
select is working perfectly fine but how to update the data already in the incidents table .......

sambhav jain
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-07-03 : 15:53:32
[code]

Update I Set
Initiator = E.Empname ,
Initdept = E.Title
From Incidents I Inner Join
Employee E
On I.Pk = E.Pk
[/code]

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

Sambhav
Starting Member

31 Posts

Posted - 2007-07-05 : 17:39:05
Thanks i got it !!

sambhav jain
Go to Top of Page
   

- Advertisement -