Click here to Skip to main content
15,888,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello

i create a view in sql server 2005 with two following tables :

table A : three columns id [numeric],date [datetime],nameID [varchar]

table B : two column id [numric], name [varchar]

view sql query following :

MSIL
CREATE VIEW [dbo].[AB]
AS
SELECT A.id,(select name from B where b.id in (a.nameID)) as names from A
GO


but occurred some error . How to solve this problem ?

please help
Posted
Comments
wizardzz 6-Jul-11 12:44pm    
Advice for the future, if you get an error, post it. Errors exist to give people the ability to solve the problem, they *usually* don't consist of randomness.
Uday P.Singh 6-Jul-11 12:49pm    
what error message are you getting?

1 solution

Chances are you are returning more than one name from B

Try:
SELECT A.id, B.name as names
FROM A 
INNER JOIN B ON A.nameID = B.id
 
Share this answer
 
Comments
fjdiewornncalwe 6-Jul-11 14:38pm    
+5. Exactly the way this should be done. Nested queries are almost always problematic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900