Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4116052
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:39:38+00:00 2026-05-20T22:39:38+00:00

I have a PHP application which runs a large set of SQL files. It

  • 0

I have a PHP application which runs a large set of SQL files. It runs all of them successfully apart from this one which returns the result “1” as apposed to an array of objects. Is there a syntax issue with this sql?

set datefirst 1;

select  top 10 artistlabel_name
        , album_name
        , releasedate
        , label
        , sum(units) total_units
        , sum(sales) total_sales 
from    (
          select  c.[name] album_name
                  , isnull(d.[name]
                  , e.[name]) artistlabel_name
                  , c.releasedate
                  , e.[name] label
                  , sum(b.price) sales
                  , count(b.Id) units 
          from    [order] a 
                  left join orderalbum b on b.orderId = a.Id
                  left join album c on b.albumId = c.Id
                  left join label e on c.labelId = e.Id
                  left outer join artist d on c.artistId = d.Id
          where   a.successful=1
                  and datepart(ww, a.OrderDate) = datepart(ww, getDate())-1
                  and datepart(yyyy, a.OrderDate) = datepart(yyyy, getDate())
          group by 
                  c.[name]
                  , isnull(d.[name], ,e.[name])
                  , c.releasedate
                  , e.[name]
          union
          select  e.[name] album_name
                  , isnull(d.[name], f.[name]) artistlabel_name
                  , e.releasedate
                  , f.[name] label
                  , sum(b.price) sales
                  , count(b.Id) units 
          from    [order] a left join orderalbum b on b.orderId = a.Id
                  left join albumvariant c on b.albumvariantId = c.Id
                  left join album e on c.albumId = e.Id
                  left join label f on e.labelId = f.Id
                  left outer join artist d on e.artistId = d.Id
          where   a.successful=1
                  and datepart(ww, a.OrderDate) = datepart(ww, getDate())-1
                  and datepart(yyyy, a.OrderDate) = datepart(yyyy, getDate())
          group by 
                  e.[name]
                  , isnull(d.[name], f.[name])
                  , e.releasedate
                  , f.[name]
        ) x
group by 
        x.album_name, 
        x.artistlabel_name, 
        x.releasedate, 
        x.label
having  sum(x.sales) > 0 
        and album_name is not null
order by 
        total_units desc;

Hopefully there’s an MSSQL ninja out there who can help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:39:38+00:00Added an answer on May 20, 2026 at 10:39 pm

    I would imagine that this query is returning two result sets, the first from set datefirst 1; and then the second.

    Read the second result set in your PHP application.

    http://php.net/manual/en/function.mssql-next-result.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a application which runs over browser ...php application... i need to lock
I have a PHP web application which uses a MySQL database for object tagging,
I have a basic ajax application, which will not work, instead the php code
I have a Php application using stream_socket_client(), to get data through tcp from a
We have a php/mysql based application which has slightly different instances for a number
I have to develop an application for the Motorola MC70 which runs Microsoft Windows
We have an existing PHP page (from an earlier project) which could be described
I have a online PHP application to which I want that the Admin should
I have a PHP application where I set $_SESSION['user']=logged once a user is authenticated.
I have a PHP application that displays a list of options to a user.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.