vikuba Posted November 14, 2013 Report Posted November 14, 2013 wat if there are 195 countries mayya? itla case specific ga istey opukuntaleru declare @table1 table ( country char(10), person char(1), countryid int ) declare @table2 table ( country char(20), countryid int ) insert into @table1 values('India', 'A', 1) insert into @table1 values('USA', 'B', 2) insert into @table1 values('Africa', 'C', 3) insert into @table2 values('India-AP', 1) insert into @table2 values('India-MP', 1) insert into @table2 values('India-UP', 1) insert into @table2 values('USA-Texas', 2) insert into @table2 values('USA-California', 2) insert into @table2 values('USA-NY', 2) insert into @table2 values('Africa-Zim', 3) insert into @table2 values('Africa-Ang', 3) select b.country, a.person, a.countryid from @table1 a inner join @table2 b on a.countryid = b.countryid
vikuba Posted November 14, 2013 Report Posted November 14, 2013 get unique country values of countries from the first table.. and write the case specific..one time ki shd be done..kadha. later u can write a generic one..
Gutka_Mukesh Posted November 14, 2013 Author Report Posted November 14, 2013 this is working for the below query... Naa data ki apply chesthe... eee error vasthundi// Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the nvarchar value 'BCD194' to data type int. declare @table1 table ( country char(10), person char(1), countryid int ) declare @table2 table ( country char(20), countryid int ) insert into @table1 values('India', 'A', 1) insert into @table1 values('USA', 'B', 2) insert into @table1 values('Africa', 'C', 3) insert into @table2 values('India-AP', 1) insert into @table2 values('India-MP', 1) insert into @table2 values('India-UP', 1) insert into @table2 values('USA-Texas', 2) insert into @table2 values('USA-California', 2) insert into @table2 values('USA-NY', 2) insert into @table2 values('Africa-Zim', 3) insert into @table2 values('Africa-Ang', 3) select b.country, a.person, a.countryid from @table1 a inner join @table2 b on a.countryid = b.countryid
chillax Posted November 14, 2013 Report Posted November 14, 2013 Thanks for replying man... logic not working man... Use the Id in the temp table to insert new rows in the 3rd table... Em not working dude... Neeku kavalasina colums select chesuko query nunchi Slelect b.country, a. Person, a. Countryid from maintable a, temptable b Where substr(b.country,1,instr(b.country,'-')-1)=a.country Nenu mobile dbing , inthakanna ekkuva type cheyalenu dude, sorry
vikuba Posted November 14, 2013 Report Posted November 14, 2013 this is working for the below query... Naa data ki apply chesthe... eee error vasthundi// Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the nvarchar value 'BCD194' to data type int. datatypes lo emaina theda undhi emo chudu.. u have to convert to Char everything.
SUbba LIngam Posted November 14, 2013 Report Posted November 14, 2013 try this man,,,,,,,,, select t.country, c.person, t.countryID from temp t left outer join country c on c.country = (substr(t.country, 1, instr(t.country, '-')-1))
Gutka_Mukesh Posted November 14, 2013 Author Report Posted November 14, 2013 Mans thank you for replying... I want to make this simple.... consider this... Fist Table data ID ProjectName 1 A 1 B 1 C second table data ID ProjectName Name 1 A John Naku kavalasina result... ID ProjecName Name 1 A John 1 B John 1 C John try this man,,,,,,,,, select t.country, c.person, t.countryID from temp t left outer join country c on c.country = (substr(t.country, 1, instr(t.country, '-')-1)) datatypes lo emaina theda undhi emo chudu.. u have to convert to Char everything. Em not working dude... Neeku kavalasina colums select chesuko query nunchi Slelect b.country, a. Person, a. Countryid from maintable a, temptable b Where substr(b.country,1,instr(b.country,'-')-1)=a.country Nenu mobile dbing , inthakanna ekkuva type cheyalenu dude, sorry
Gutka_Mukesh Posted November 14, 2013 Author Report Posted November 14, 2013 Changed the first post... want to make this simple.. I want to make this simple.... consider this... Fist Table data ID ProjectName 1 A 1 B 1 C second table data ID ProjectName Name 1 A John Naku kavalasina result... ID ProjectName Name 1 A John 1 B John 1 C John Please help... very urgent.. CITI#H@ CITI#H@
ChampakDas Posted November 14, 2013 Report Posted November 14, 2013 ante anni countries, ani states ki oka line vastundi...how feasible it is? well he can write the query with String identification rite.. if substring(country,4 = INDI) then ...A ani pettestey aipothadi. so appdu value update aiy ey state vachina country same kabatti...it works..
ChampakDas Posted November 14, 2013 Report Posted November 14, 2013 ardam itale tum kya maladutundi... Thanks for replying man.. em anukokunda okka sari naa question chudava?? First table lo unna person ni... 3rd table data loki marchali... using country ID in the second table... Single records for persons... unna first table.. multiple records laaga maarali...
Gutka_Mukesh Posted November 14, 2013 Author Report Posted November 14, 2013 ardam itale tum kya maladutundi... Please see the first post man... update chesina... Thank you`
ChampakDas Posted November 14, 2013 Report Posted November 14, 2013 create table A (ID int, ProjectName varchar(10)) insert into a values(1,'A') insert into a values(1,'B') insert into a values(1,'C') insert into a values(1,'A','John') select * from abc create table b (id int, ProjectName varchar(50), Name varchar(10)) SELECT A.ID,A.ProjectName,B.Name FROM A A JOIN B B ON A.ID=B.ID Mans thank you for replying... I want to make this simple.... consider this... Fist Table data ID ProjectName 1 A 1 B 1 C second table data ID ProjectName Name 1 A John Naku kavalasina result... ID ProjecName Name 1 A John 1 B John 1 C John
loveindia Posted November 14, 2013 Report Posted November 14, 2013 Gatis man.. His id's are not bigint only man.. in his test he is giving like that and expecting the query for that.. requirement looks wrong from his side.. so far as I see it it is just a straight inner join between the two tables. Nothing more than that.
loveindia Posted November 14, 2013 Report Posted November 14, 2013 wat if there are 195 countries mayya? itla case specific ga istey opukuntaleru My query was not case specific dude.. d one u wrote was.. there's something missing from the post.. he is unable to make us understand Original poster, Csn u put some real data and give us ddl with insert statements so that we can make it faster.
Gutka_Mukesh Posted November 14, 2013 Author Report Posted November 14, 2013 Gatis man.. His id's are not bigint only man.. in his test he is giving like that and expecting the query for that.. requirement looks wrong from his side.. so far as I see it it is just a straight inner join between the two tables. Nothing more than that. Thanks a lot for replying man... its an inner join... I got what I needed... AFDB ))(<
Recommended Posts