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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:24:05+00:00 2026-06-03T06:24:05+00:00

I am trying to sort my data by certain groups of people. My Data

  • 0

I am trying to sort my data by certain groups of people. My Data Looks Like:

Origional_Date  ID      FORM    Total
2012-03-01      1855    3       1283
2012-03-01      2869    4       2306
2012-03-01      5555    4       6440
2012-03-01      5555    3       8373
2012-03-01      2527    3       8476
2012-03-01      922     3       823
2012-03-15      2907    4       1420
2012-03-15      5555    3       2892
2012-03-15      2914    4       5008
2012-03-15      2375    3       4594

The Query I have so far is:

DECLARE @StartDate smalldatetime, @EndDate smalldatetime, @Web_ID as smallint
    SET @StartDate = '20120301'
    SET @EndDate = '20120331'
    SET @Web_ID = '5555'

SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, [Origional_Date]), -1) as [Origional_Date]
  ,[ID]
  ,[Form]
  ,SUM([Total]) as [Total]
  FROM mytable
  WHERE [Origional_Date] between @StartDate and @EndDate
    AND [ID] = @Web_ID
  GROUP BY DATEADD(WEEK, DATEDIFF(WEEK, 0, [Origional_Date]), -1), [ID], [Form]
  ORDER BY [Origional_Date], [Form] ASC

What I am trying to do is display my data like:

Origional_Date  ID      FORM    Total
2012-03-01      Web     3       8373
2012-03-01      Direct  3       10582
2012-03-01      Web     4       6440
2012-03-01      Direct  4       2306
2012-03-15      WEB     3       2892
2012-03-15      Direct  3       4594
2012-03-15      Direct  4       6428

Where Web is ID 5555 and Direct is anything else.

I am just not sure how if this can be done with an “IF” statement or if it needs to be done in the “group by”

THANK YOU!

  • 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-06-03T06:24:06+00:00Added an answer on June 3, 2026 at 6:24 am

    Using Case clausule

    select case active
        when 1 then 'Active'
        when 0 then 'Inactive'
        end         
    from contract
    

    in your case is similar of this:

    select case [ID]
        when 5555 then 'Web'
        else 'Direct'
        end as [ID]
    from mytable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to sort mysql data with alphabeticaly like A | B |
I am trying to sort data which is from Generic List object. By using
I am using celltable of GWT. And I am trying to sort a data
I'm trying to sort a column of data in a GTK tree view non-alphabetically.
I am trying to sort a list based on data attributes with tinysort .
I am trying to sort an array. I have an array of data, where
I am trying to figure out how to sort a multidimensional data (5 dimensions)
I am trying to read and sort a csv file that has data that
Well I am trying to sort some data in PHP. Here is an example
I'm using NHibernate as my ORM and I'm trying to sort some data. The

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.