Friday, February 24, 2012

How do I do this query

I have 3 tables
Users
Customerid - guid
userid - varchar
customertoworker
customerid - FK
workerid - FK
extract
customerid - guid
data layout
extract
EACFF367-8E73-4C4C-A9A7-036A0D7E57AB
customertoworker
EACFF367-8E73-4C4C-A9A7-036A0D7E57AB, 90ED4230-2711-4019-A2AD-071D52891BBF
EACFF367-8E73-4C4C-A9A7-036A0D7E57AB, 873762AB-34BD-455B-83B2-137645BE3331
users
EACFF367-8E73-4C4C-A9A7-036A0D7E57AB , RAINMAN
90ED4230-2711-4019-A2AD-071D52891BBF , BOB
873762AB-34BD-455B-83B2-137645BE3331 , JAMES
I want the data to appear in 1 row. I want to know the workers that all
users in the extract have in 1 row.
ex
RAINMAN, BOB, JAMES
select x.userid, z.userid,x.customerid
from cdtextractactivemlm x
inner join customertoworker y
on x.customerid = y.customerid
inner join useridentifier z
on z.customerid = y.workerid
order by y.customerid
The query above gives me 2 rows... can someone shed some light...
thanks for the help.Look at this example (and remember: this breaks normalization and should be
used for presentation purposes only):
http://milambda.blogspot.com/2005/0...s-as-array.html
ML
http://milambda.blogspot.com/|||niv
I understood from your narritave nothing, sorry
If you say that your query returns two rows , so try using TOP 1 clause to
get only one row as well as using ORDER BY clause to sort the output
"niv" <niv@.discussions.microsoft.com> wrote in message
news:D76674C3-3CB4-43F8-B0E0-CA8A85E3DC2F@.microsoft.com...
>I have 3 tables
> Users
> Customerid - guid
> userid - varchar
> customertoworker
> customerid - FK
> workerid - FK
>
> extract
> customerid - guid
> data layout
> extract
> EACFF367-8E73-4C4C-A9A7-036A0D7E57AB
> customertoworker
> EACFF367-8E73-4C4C-A9A7-036A0D7E57AB, 90ED4230-2711-4019-A2AD-071D52891BBF
> EACFF367-8E73-4C4C-A9A7-036A0D7E57AB, 873762AB-34BD-455B-83B2-137645BE3331
> users
> EACFF367-8E73-4C4C-A9A7-036A0D7E57AB , RAINMAN
> 90ED4230-2711-4019-A2AD-071D52891BBF , BOB
> 873762AB-34BD-455B-83B2-137645BE3331 , JAMES
> I want the data to appear in 1 row. I want to know the workers that all
> users in the extract have in 1 row.
> ex
> RAINMAN, BOB, JAMES
> select x.userid, z.userid,x.customerid
> from cdtextractactivemlm x
> inner join customertoworker y
> on x.customerid = y.customerid
> inner join useridentifier z
> on z.customerid = y.workerid
> order by y.customerid
> The query above gives me 2 rows... can someone shed some light...
> thanks for the help.|||I am using sql 2000.
This is a function written in sql?
Are there any others ways of getting the data into the format I want?
"ML" wrote:

> Look at this example (and remember: this breaks normalization and should b
e
> used for presentation purposes only):
> http://milambda.blogspot.com/2005/0...s-as-array.html
>
> ML
> --
> http://milambda.blogspot.com/|||Pure T-SQL user-defined function. Works in SQL 2000 and above.
The usual way would be to do it on the client (in the application tier).
ML
http://milambda.blogspot.com/|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are.
I will not even comment on that insane use of GUIDs and the single
character user_id, but what you are doing is a violation of 1NF.
Display is done in the front and not in the database. You are
basically not writing SQL at all.

No comments:

Post a Comment