Mike
Mike

Reputation: 1067

How to retrieve multiple data in a column of a table using a query?

I have 2 tables named as master and kpi.
Master table has following columns

no, name, dtStart, dtEnd, status, user and dtCreate

kpi table has following columns

no and kpName

"no" in kpi table refers "no" in master table

What i expect to do is, when I select a name from the dropdownlist relevant details in both tables should be displayed.
One name has unique "no". Also "no" can have multiple kpNames.
Please help me.

Upvotes: 1

Views: 869

Answers (3)

Shah Hassan
Shah Hassan

Reputation: 155

You have to make a stored procedure and then join both tables. Here is sample

create proc Details
begin
@Name char(50)
select * from Master m join kpi n ON
 m.no==n.no where Name== @Name
end

Upvotes: 2

Mansoor
Mansoor

Reputation: 4192

SELECT table1.[no], table1.name, table1.dtStart, table1.dtEnd, 
table1.[status], table1.[user] , table1.dtCreate ,table2.kpName 
FROM masterTable [table1] 
INNER JOIN kpiTable [table2] 
ON table1.[no] = table2.[no] 
WHERE table2.Name = 'Your Selected value'

Upvotes: 1

James
James

Reputation: 729

try this:

SELECT a.[no], a.name, a.dtStart, a.dtEnd, a.[status], a.[user] , a.dtCreate 
From masterTable  a 
Inner JOIN kpiTable b ON a.[no] = b.[no]
Where b.Name = 'dropDownSelectedValueName'

Upvotes: 2

Related Questions