I thoroughly agree with Richard. The database design is poor. It would be much easier to work with if the database were properly designed and proper primary/foreign key relationships established.
However, you can accomplish what you want given the current design. This solution depends on the data being consistently entered in table2 as comma or space separated numbers.
[tt]
Select *
From table1 t1, table2 t2
Where ltrim(str(t2.authorsid))=t1.authorsid
Or charindex(','+ltrim(str(t2.authorsid))+',', t1.authorsid)>0
Or charindex(' '+ltrim(str(t2.authorsid))+',', t1.authorsid)>0
Or charindex(','+ltrim(str(t2.authorsid))+' ', t1.authorsid)>0
Or charindex(' '+ltrim(str(t2.authorsid))+' ', t1.authorsid)>0
Or ltrim(str(t2.authorsid))=
case charindex(',',t1.authorsid)
When 0 Then ''
Else left(t1.authorsid,charindex(',',t1.authorsid)-1) End
Or ltrim(str(t2.authorsid))=
case charindex(' ',t1.authorsid)
When 0 Then ''
Else left(t1.authorsid,charindex(' ',t1.authorsid)-1) End
Or ltrim(str(t2.authorsid))=
case charindex(',',t1.authorsid)
When 0 Then ''
Else right(t1.authorsid,charindex(',',reverse(t1.authorsid))-1) End
Or ltrim(str(t2.authorsid))=
case charindex(' ',t1.authorsid)
When 0 Then ''
Else right(t1.authorsid,charindex(' ',reverse(t1.authorsid))-1) End
[/tt]
Besides being ugly, this query may run very slowly for large tables. It cannot use indexes and uses several intrinsic functions repeatedly.
Let me know how it goes and if you have any questions about the query. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it if you have time.