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 6338219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:24:01+00:00 2026-05-24T19:24:01+00:00

declare @dateto as datetime set @dateto=’8/1/11′ SELECT ti.userkey, SUM(l.Price * l.OrderQty) AS SumOfOrders, count

  • 0
declare @dateto as datetime
set @dateto='8/1/11'

SELECT     ti.userkey, SUM(l.Price * l.OrderQty) AS SumOfOrders, count (distinct ti.orderid) AS Ordercount
FROM         SOLine AS l WITH (nolock) LEFT OUTER JOIN
             SOImported AS ti ON ti.OrderId = l.OrderId LEFT OUTER JOIN
             Sale AS o ON o.SaleId = ti.Inventory_Id
  Where ti.createddate < @DateTo                
 GROUP BY ti.userkey, o.WootSiteId

Need this query to bucket order count like the following:

Group          userkeycount   sumoforders
 1 trans
 2-30
 31-60
 61-90
 91-120
 121-150
 151-180
 181-210
 211-240
 241-270
 271-300
 301-330
 331-360
 360 or More
  • 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-24T19:24:02+00:00Added an answer on May 24, 2026 at 7:24 pm
    declare @dateto as datetime
    set @dateto='8/1/11'
    
    SELECT 
        CASE WHEN Ordercount >= 360 THEN '360 or More'
             WHEN Ordercount = 1 THEN '1 trans'
             ELSE CAST (30 * FLOOR(Ordercount / 30) AS VARCHAR) + '-' + CAST (30 * CEILING (Ordercount / 30) AS VARCHAR)
        END grp,
        COUNT(*) userkeycount,
        SUM(SumOfOrders) SumOfOrders
    FROM (
        SELECT ti.userkey,
            SUM(l.Price * l.OrderQty) AS SumOfOrders,
            count (distinct ti.orderid) AS Ordercount
        FROM         SOLine AS l WITH (nolock) LEFT OUTER JOIN
                     SOImported AS ti ON ti.OrderId = l.OrderId LEFT OUTER JOIN
                     Sale AS o ON o.SaleId = ti.Inventory_Id
         Where ti.createddate < @DateTo
         GROUP BY ti.userkey
    ) rs
    GROUP BY CASE WHEN Ordercount >= 360 THEN '360 or More'
             WHEN Ordercount = 1 THEN '1 trans'
             ELSE CAST (30 * FLOOR(Ordercount / 30) AS VARCHAR) + '-' + CAST (30 * CEILING (Ordercount / 30) AS VARCHAR)
        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Declare @count nvarchar(max) set @count ='select COUNT(*) from '+ @tablename+'' if( @count =0 )
declare @data datetime set @data = '2011-01-01 23:59:59:999' select @data result is: 2011-01-02 00:00:00.000
DECLARE @StartTime datetime,@EndTime datetime SELECT @StartTime=GETDATE() select distinct born_on.name from born_on,died_on where (FLOOR(('2012-01-30'-born_on.DOB)/365.25) <=
declare @servername varchar(2000) set @EmriServerit=(select @@servername) declare @dbname varchar(2000) set @dbname ='Test1' declare @Dir
declare @var sysname declare @sql varchar(5000) set @var = 'Table_name' set @sql = 'select
DECLARE @OrdersTemp TABLE ( OrderId UNIQUEIDENTIFIER ) INSERT INTO @OrdersTemp SELECT ord.Id FROM Orders
declare @customerID int set @customerID=1 ;with cteDates as ( select dateadd(hh, datediff(hh, 0, getdate()),
DECLARE @ActionNumber varchar(20)='EHPL-DES-SQ-1021' set @ActionNumber=(select top 1 * from dbo.ANOSplit(@ActionNumber,'-') order by ROW_NUMBER() OVER
declare @test varchar(20) set @test = 'VALUE' exec(' select '+@test+' ') This returns: Invalid
declare @a varchar(40) set @a='1.23e-4' declare @b decimal(27,12) if isnumeric(@a) =1 begin select @b=cast(@a

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.