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
 how to join two tables having no common coloumn

Author  Topic 

jitupatil_2007
Starting Member

1 Post

Posted - 2008-04-15 : 07:45:27
hi friends i am new to this forum and to the tech. also , i am reading a csv file and storing the data to the table of sql server 2005 database but the problem is i cannot join both the tables because both the tables doesnot have common cols and ther is no primary key field in any of the coloumn i have tried the sql query but i didn't got the desired output so could anyone help me please see the sql query of mine is like this:

SELECT dbo.table1.country, dbo.table1.code, dbo.table1.rate_min, dbo.table2.start_date_time, dbo.table2.rounded_dur, dbo.table2.cost,
dbo.table2.dialed_digits
FROM dbo.table1 INNER JOIN
dbo.table2 ON dbo.table1.code = SUBSTRING(dbo.table2.dialed_digits, 1, 2) OR
dbo.table1.code = SUBSTRING(dbo.table2.dialed_digits, 1, 3) OR
dbo.table1.code = SUBSTRING(dbo.table2.dialed_digits, 1, 4) OR
dbo.table1.code = SUBSTRING(dbo.table2.dialed_digits, 1, 5) OR
dbo.table1.code = SUBSTRING(dbo.table2.dialed_digits, 1, 6)

please help me its urgent

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-04-15 : 07:47:43
can you provide some sample data to show how they should join together then? we can't tell just from your query

Em
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-15 : 08:05:48
[code]SELECT t1.Country,
t1.Code,
t1.Rate_Min,
t2.Start_Date_Time,
t2.Rounded_Dur,
t2.Cost,
t2.Dialed_Digits
FROM dbo.Table1 AS t1
INNER JOIN dbo.Table2 AS t2 ON LEFT(t2.Dialed_Digits, 6) LIKE t1.Code + '%'[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-15 : 09:44:15
Can we replace LEFT(t2.Dialed_Digits, 6) LIKE t1.Code + '%' with t2.Dialed_Digits LIKE t1.Code + '%' ?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -