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

  • Home
  • SEARCH
  • 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 6990391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:20:35+00:00 2026-05-27T19:20:35+00:00

First of all, my table structure is something similar like this: CREATE TABLE Testing(

  • 0

First of all, my table structure is something similar like this:

CREATE TABLE Testing(
       [ID]        NVARCHAR(50),
       [DATE]      DATETIME,
       [TOTAL]     INT,
       [ITEM]      NVARCHAR(50),
       [Warehouse] NVARCHAR(50)
)ON[PRIMARY]

I put some sample here:

[ID] [Date]      [Total] [Item] [Warehouse]
1    2011-04-04  400     A0001   B12
2    2011-05-04  500     A0001   B13
3    2011-04-30  400     A0001   B12
4    2011-04-25  400     A0001   B13
5    2011-06-05  600     A0001   B12
6    2011-03-02  300     A0001   B11
7    2011-05-28  500     A0001   B13   

I am trying to group by [Item] and [Warehouse] and [Date] by month as well
For example output:

The result should be like this

[Date]        [Total]   [Item]  [Warehouse]
March 2011     300       A0001   B11
April 2011     800       A0001   B12
June 2011      500       A0001   B12
April 2011     400       A0001   B13
May 2011       1000      A0001   B13

I tried the sql something like, that i parse in month and year part to made the selection

SELECT [Item],[Warehouse],SUM(Total) AS Total
FROM [Testing]
WHERE Datepart(month,[Date]) = 4 AND DATEPART(year,[Date]) = 2011
GROUP BY [Item],[Warehouse]

I get the expected result?Is there any way to do? i actually trying to came out a close balance for each month and year by distinct of warehouse and item?

Sound to me its need to loop through a prefix table..
Its that anyway to do so?

Thanks

Regards
Liangck

  • 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-27T19:20:36+00:00Added an answer on May 27, 2026 at 7:20 pm

    I think that formatting date on SQL Server side is (usually) a bed idea, but anyway you can try:

    select datename(mm, dateadd(m, datediff(m, 0, [date]), 0)) + ' ' +
          select cast(datepart(yy, dateadd(m, datediff(m, 0, [date]), 0)) as varchar)
          [date] sum(total) as total, item,warehouse
    from testing
    group by item, warehouse, dateadd(m, datediff(m, 0, [date]), 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say my table structure looks something like this: CREATE TABLE [dbo].[table1] ( [id]
I have an existing table structure that looks something like this: AnimalTable ------------- |Id
Say I got an traditional SQL structure like so: create table tags (id PRIMARY
I have a data structure something like this: typedef struct tagSUB_DATA { double measuredValue;
I have this table structure: CREATE TABLE users ( uid bigint NOT NULL, first_name
First of all, let's define a few tables: Users table will store information about
First i gave all values of row in JTAble. While inserting table values into
Is it possible to display all but first row from a table in sql
Using jQuery, how do I delete all rows in a table except the first?
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built

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.