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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Subquery returned more than 1 value

Author  Topic 

maxim
Yak Posting Veteran

51 Posts

Posted - 2007-05-24 : 20:41:02
Hello, I have a very basic question (I think...)

I will simplify my problem:

I have two tables

tbl_users:
usrID int, usrName varchar(100)

tbl_cars:
usrID int, carID int

Some Users have more than one car, but i want to generate a table from an sqlProcedure with:

UsrID | UsrName | UsrCarsID's:
12 | mike | 1, 3, 4

How can I select all cars that one user have on a subQuery?

I hope you understand me...

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-24 : 21:17:11
see here http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx
create a UDF to return the CarsID in CSV


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-26 : 03:53:41
Alternatively, if you use front end application, you can easily concatenate data there
Where do you want to show data?

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-26 : 03:54:56
Your subject sounds that you got that error

Madhivanan

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

maxim
Yak Posting Veteran

51 Posts

Posted - 2007-05-29 : 21:10:35
Thanks!!

That UDF (posted by khtan) solve my problem.

madhivanan, i use a front-end application but i prefer to manage all the data in one sqlProcedure.

If i had used an front-end app, and if i have a table with 200 users I needed 200 new connections to receive all the cars of wich one!

With UDF, i only need one connection!

Thanks to both.
(Sorry my bad english)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-29 : 22:15:23
>>If i had used an front-end app, and if i have a table with 200 users I needed 200 new connections to receive all the cars of wich one!

No ... you just need a single SQL statement, with a single connection. Why would you think you need 1 connection per row????



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -