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
 Inter Join Query

Author  Topic 

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-01 : 08:15:21
I need to update a field from another Table. The situation is that There are three tables in my db
1st have the Fields of NameID & classID & Books
2nd have the Fields of NameID & SectionID,
3RD have the Fields of SectionID

I want to add new field in the 3rd table named Books by setting NameID. kindly provide the script to addthe field.

Feejaz

Navi

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-01 : 08:34:14
quote:
I want to add new field in the 3rd table named Books by setting NameID. kindly provide the script to addthe field.

You want to add a new field in the 3rd table ? use alter table synxtax

alter table table3 add books varchar(100)


quote:
by setting NameID

what do you mean by this ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-03 : 01:42:44
I want to Update the Third Table's Field (Books) according to the NameID, But there is no NameID in the third table therefore Ihave to join 2nd table in which SectionID & NameID exists.

Feejaz

Navi
Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-03 : 01:44:59
I want to get data also as in Ist Table's field(Books) in the third table's new field Books.

Feejaz

Navi
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-03 : 01:52:38
[code]update t3
set books = t1.books
from table1 t1
inner join table2 t2 on t1.nameid = t2.nameid
inner join table3 t3 on t2.sectinoid = t3.sectionid[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-03 : 02:41:59
I have the following actual Table
District, School & Line
I want to update line's field (Menu) as per data of District's field (MenuName)but there is no commen ID between both of them therefore I used a third table in which the both ID are available and I make a code as per your given example that is I think would be like this
update L
set Menu = D.MenuName
from District D
inner join School S on D.SchoolID = S.SchoolID
inner join Line L on S.LineID = L.LineID

But I am getting error on this code that is

Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'SchoolID'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'LineID'.

Kindly correct my code.

Feejaz

Navi
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2007-12-03 : 02:49:34
your error suggests that those column names are wrong / do not appear in those tables. can you script / list out your tables and columns?

Em
Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-03 : 03:05:57
OK
Thats nice you r good. Now it is working fine. But Can u tell me how I can the field not null by default this field is null.

Feejaz

Navi
Go to Top of Page

sharkie
Starting Member

6 Posts

Posted - 2007-12-03 : 07:05:20
Not sure what you mean but if you want to make the value 0 from a NULL use the following code.

ISNULL(columnName, 0) AS AliasName
Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-04 : 00:02:41
Thanks
But I want to ask about how to make a field not null. Because all the rows of this fields have value Now I want to not null it. But When I clear null check from the wizard. Reply a exception that you cannot assign not null.

Feejaz.

Navi
Go to Top of Page
   

- Advertisement -