| 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 db1st have the Fields of NameID & classID & Books 2nd have the Fields of NameID & SectionID,3RD have the Fields of SectionIDI want to add new field in the 3rd table named Books by setting NameID. kindly provide the script to addthe field.FeejazNavi |
|
|
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 synxtaxalter table table3 add books varchar(100) quote: by setting NameID
what do you mean by this ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
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.FeejazNavi |
 |
|
|
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.FeejazNavi |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-03 : 01:52:38
|
[code]update t3set books = t1.booksfrom table1 t1 inner join table2 t2 on t1.nameid = t2.nameidinner join table3 t3 on t2.sectinoid = t3.sectionid[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
feejaz
Yak Posting Veteran
68 Posts |
Posted - 2007-12-03 : 02:41:59
|
| I have the following actual TableDistrict, School & LineI 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 Lset Menu = D.MenuNamefrom District D inner join School S on D.SchoolID = S.SchoolIDinner join Line L on S.LineID = L.LineIDBut I am getting error on this code that is Server: Msg 207, Level 16, State 3, Line 1Invalid column name 'SchoolID'.Server: Msg 207, Level 16, State 1, Line 1Invalid column name 'LineID'.Kindly correct my code.FeejazNavi |
 |
|
|
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 |
 |
|
|
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.FeejazNavi |
 |
|
|
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 |
 |
|
|
feejaz
Yak Posting Veteran
68 Posts |
Posted - 2007-12-04 : 00:02:41
|
| ThanksBut 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 |
 |
|
|
|