Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subquery error

Status
Not open for further replies.

magmo

Programmer
May 26, 2004
291
0
0
SE
Hi


I try to run the following query..

Code:
SELECT
(SELECT DISTINCT Artno, L, D, CreatedBy FROM dbo.tbl_Art WHERE (L = N'SE')) AS SE,
(SELECT DISTINCT Artno, L, D, CreatedBy FROM dbo.tbl_Art WHERE (L = N'GB')) AS GB
FROM  dbo.tbl_Art


But I get a error message telling me..."only one expression can be specified in the selected list when the subquery is not introduced with exsits"


What do I need to change to get this to work?


Regards
 
what you need to change depends on what you actually want

SELECT DISTINCT Artno, L, D, CreatedBy
FROM dbo.tbl_Art
WHERE L IN ( N'SE', N'GB')

the DISTINCT should probably be removed too

r937.com | rudy.ca
 
Hi


If I run a SELECT * FROM Artno I get this...

Artno L
123 GB
123 ES
456 GB
789 FR

But I would like to have it like this...

ES GB FR

123 123
456

789




Hope this make sence, is this possible?
 
Code:
SELECT max(case when L = 'ES'
                then cast(Artno as varchar)
                else ''
            end) as ES   
     , max(case when L = 'GB'
                then cast(Artno as varchar)
                else ''
            end) as GB   
    , max(case when L = 'FR'
                then cast(Artno as varchar)
                else ''
            end) as FR   
  FROM dbo.tbl_Art 
group
    by Artno

r937.com | rudy.ca
 
Hi


Just perfect! Thank you so much.


Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top