-1

I tried to send the following query to a MSSQL Server using Doctrine in Symfony:

DECLARE @ebayitems TABLE (kartikel INT, cartnr VARCHAR(255), ebayPrice DECIMAL(10,2), ebayID VARCHAR(255))
DECLARE @amazonitems TABLE (kartikel INT, cartnr VARCHAR(255), amazonPrice DECIMAL(10,2), amazonPriceVersand DECIMAL(10,2), amazonASIN VARCHAR(255))
DECLARE @shopitems TABLE (kartikel INT, cartnr VARCHAR(255), ebayPrice DECIMAL(10,2), latestEbayID VARCHAR(255), amazonPrice DECIMAL(10,2), latestAmazonASIN VARCHAR(255))

INSERT INTO @ebayitems
select tArt.kartikel, tArt.cartnr, ebay.ebay_price AS ebayPrice, ebay.ItemID AS ebayID
...
                GROUP BY tArt.kartikel, tArt.cartnr, ebay.ebay_price, ebay.ItemID
                
INSERT INTO @amazonitems                
select tArt.kartikel, tArt.cartnr, amazon.fprice, CASE WHEN amazon.fprice < 315 THEN amazon.fprice + 4.90 ELSE amazon.fprice + 5.90 end AS amazonPrice, amazon.casin1 AS AmazonASIN
...
                GROUP BY tArt.kartikel, tArt.cartnr, amazon.fprice, amazon.casin1                              

INSERT INTO @shopitems
SELECT ebayitems.kartikel, ebayitems.cartnr, ebayPrice, MAX(ebayID) AS latestEbayID, amazonitems.amazonPriceVersand, max(amazonitems.amazonASIN) AS latestAmazonASIN 
... 
GROUP BY ebayitems.kartikel, ebayitems.cartnr, ebayPrice, amazonitems.amazonPriceVersand

SELECT items.cartnr, 
            tPreis.kpreis AS kpreis,
            (CASE WHEN ebayPrice > amazonPrice THEN (FLOOR(MIN(amazonPrice) * 0.95)-0.10) / 1.19 
                            ELSE (FLOOR(MIN(ebayPrice) * 0.95)-0.10) / 1.19 END) AS shoppreis, 
            ebayprice, 
            latestEbayID, 
            amazonprice, 
            latestAmazonASIN
...
        GROUP BY items.cartnr, kpreis, ebayprice, 
            latestEbayID, 
            amazonprice, 
            latestAmazonASIN

and I get the error from the title.

If I run the whole thing from HeidiSQL it works perfect but if I try the following code it won't (the $conn variable is correctly set, the connection is working)

$items = $conn->executeQuery($selectSQL);

var_dump($items->fetchAllAssociative());

Anyone has any idea about what should I do?

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 1
    try adding: SET NOCOUNT ON; at the start of your long statement – siggemannen Mar 15 '23 at 12:02
  • Please do not add answers to the question body itself. Instead, you should add it as an answer. [Answering your own question is allowed and even encouraged](https://stackoverflow.com/help/self-answer). – Adriaan Mar 15 '23 at 13:23

1 Answers1

0

I added SET NOCOUNT ON; at the beggining as @siggemannen suggested and it worked. The error is now gone. Thanks for the help!