Jump to content

Need help with inner select "Subquery returned more than 1 value"


Legioona

Recommended Posts

Hello,

 

my query is as follows:

 

SELECT

 

businesskey as SAPID,

fulladdress as SAPaddress,

joinid,

 

 

(SELECT mmdb.dbo.shippingcompany.fulladdress FROM mmdb.dbo.shippingcompany WHERE mmdb.dbo.shippingcompany.shippingcompanyid =

(SELECT CASE WHEN mmdb.dbo."Join".Datasource1 = 3 THEN mmdb.dbo."Join".Join1

                WHEN mmdb.dbo."Join".Datasource2 = 3 THEN mmdb.dbo."Join".Join2

                WHEN mmdb.dbo."Join".Datasource3 = 3 THEN mmdb.dbo."Join".Join3 

                WHEN mmdb.dbo."Join".Datasource4 = 3 THEN mmdb.dbo."Join".Join4

            ELSE 0 END FROM mmdb.dbo."Join" WHERE mmdb.dbo."Join".JoinID = mmdb.dbo.shippingcompany.joinid)) AS MMDBFulladdress

 

 

FROM

 

mmdb.dbo.shippingcompany

 

WHERE

 

datasourceid = 5

and

rowstatusid = 1

and

joinid <> - 1

and

shippingcompanytypeid <> 4

 

This produces an error "Subquery returned more than 1 value".

 

On the other hand, if I comment out the line:

 

(SELECT mmdb.dbo.shippingcompany.fulladdress FROM mmdb.dbo.shippingcompany WHERE mmdb.dbo.shippingcompany.shippingcompanyid =

 

and remove the extra parenthesis before the AS , it works like a charm, returning

 

10026 Ortsteil:Motzen 48635 6096

10536 Shiwei Port 47978 2130

11340 Ul. Ludowa 13 39722 12442

.

.

.

 

Why oh why doesn't the original query work?

 

All help very much appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.