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 write the inner join for multiple values ?

Author  Topic 

sivasankarp
Starting Member

4 Posts

Posted - 2009-11-25 : 02:21:53
Hi

Am new to Sql Programming

I have two tables.
ID, AID
11 2,3,4,5

I want to display AID's


I write the inner join to get the Name of AID values but am getting error(Invalid datatype conversion)

select AName from firsttable as f inner join TableA as t f.AID= t.AID(here AID is varchar so am getting the error)

How to split the numbers and join the ID

Thanks in advance


Sivasankar puppala

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 02:52:59
select AName from firsttable as f inner join TableA as t on ','+t.AID+',' like '%,'+cast(f.AID as varchar(10))+',%'

Madhivanan

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

sivasankarp
Starting Member

4 Posts

Posted - 2009-11-25 : 03:18:38
Thanks for your reply its working but i want to show AName with comma.
ex:
AID =>3,4,5
AName=>Bangalore,Hyderabad,Chennai

Sivasankar puppala
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 04:23:46
Which version of SQL Server are you using?

Madhivanan

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

peterkirubakaran
Starting Member

12 Posts

Posted - 2009-11-25 : 06:21:45
have a look at these links...


http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/

http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/

Peets
Go to Top of Page
   

- Advertisement -