Order By Not Ordering Month Names The Way I Want

Oct 17, 2007



Ok ok ok - I'm not very good at this, but I can't figure out how to get the 'order by' statement working correctly. It's ordering the 'ReportDate' column alphabetically and not by month order. Anyone help?

select id,
DATENAME(mm,ReportDate) As ReportDate,
max(items) as Items
from mytable
group by id, DATENAME(mm, ReportDate)
order by id, ReportDate


Output:-
id ReportDate Items
240 July 16024
240 June 14705
240 October 19392
240 September 18979
241 August 29542
241 July 27806
241 June 27500
241 October 30007
241 September 29961


As you can see, the months are coming out alphabetically and not in month order.

Any advice appreciated, especially constructive advice

View 6 Replies


ADVERTISEMENT

Ordering Date In Asc Order ?

Oct 12, 2006

SELECT
LEFT(CONVERT(CHAR(11),convert(datetime,task_date),109),3) + ' ' +
RIGHT(CONVERT(CHAR(11),convert(datetime,task_date),109),4) as Date,
SUM(CASE a.status_id WHEN 1000 THEN b.act_point ELSE 0 END) as Programming,
SUM(CASE a.status_id WHEN 1016 THEN b.act_point ELSE 0 END) as Design,
SUM(CASE a.status_id WHEN 1752 THEN b.act_point ELSE 0 END) as Upload,
SUM(CASE a.status_id WHEN 1032 THEN b.act_point ELSE 0 END) as Testing,
SUM(CASE a.status_id WHEN 1128 THEN b.act_point ELSE 0 END) as Meeting,
SUM(CASE a.status_id WHEN 1172 THEN b.act_point ELSE 0 END) as Others
From
task_table a,act_table b where a.status_id=b.act_id and
a.user_id=(select user_id from user_table where user_name='Raghu') and
a.task_date like '%/%/2006'
GROUP BY
LEFT(CONVERT(CHAR(11),convert(datetime,task_date),109),3) + ' ' + RIGHT(CONVERT(CHAR(11),convert(datetime,task_date),109),4)

Output :

Aug 2006 294 0 0 80 0 0
Jan 2006 14 0 0 0 0 0
Oct 2006 336 0 0 0 0 0
Sep 2006 3262 20 24 8 16 0

How to sort the date in ascending Order ?

Jan 2006
Aug 2006
Sep 2006
Oct 2006

View 5 Replies View Related

Ordering Results By Order Of The IN' Clause

Jul 28, 2006

Consider this SQL:SELECT my_field FROM my_table WHERE my_field IN ('value2', 'value1','value3')Simple enough, but is there anyway to specify that the result should beordered exactly like the "IN" clause states? So when this recordsetcomes back, I want it like this:my_field------------value2value1value3Possible?Deane

View 5 Replies View Related

Order By Month And Year

Jun 2, 2008

hai freinds ,

This is the query iam using to retrieve year and its month from a datetime column

quote:Select Distinct DateName(mm, col_datetime) as 'Month',
year(col_datetime)
as 'Year'from table_name
Order By DateName(mm, col_datetime)

result for the above query is

quote:
month year
june 2008
june 2007
july 2007
july 2008
aug 2007
aug 2008 and so on.....


but my need is

quote:
month year
june 2008
july 2008
aug 2008
june 2007
july 2007
aug 2007
and so on.....


so can someone fix it or give me a idea

thanks friends

View 3 Replies View Related

Sort Order By Month

Nov 6, 2007

SELECT TOP (100) PERCENT Calendar_Key, Calendar_Date, Calendar_Year, Calendar_Month, Calendar_Quarter, Calendar_week, Calendar_DayOfMonth,
Calendar_DayOfYear, Calendar_Datename, Calendar_EndOfMonth, Calendar_EndOfQuarter, Calendar_EndOfYear,
CAST(CASE WHEN Calendar_Month = 1 THEN 'January' WHEN Calendar_Month = 2 THEN 'February' WHEN Calendar_Month = 3 THEN 'March' WHEN Calendar_Month
= 4 THEN 'April' WHEN Calendar_Month = 5 THEN 'May' WHEN Calendar_Month = 6 THEN 'June' WHEN Calendar_Month = 7 THEN 'July' WHEN Calendar_Month
= 8 THEN 'August' WHEN Calendar_Month = 9 THEN 'September' WHEN Calendar_Month = 10 THEN 'October' WHEN Calendar_Month = 11 THEN 'November'
WHEN Calendar_Month = 12 THEN 'December' END AS char(9)) AS Month
FROM EDW.Calendar_Dim
WHERE (Calendar_Year IS NOT NULL)
ORDER BY Calendar_Year, Calendar_Month

I have two vlaue prompts.. which show year & month, when we select year, it shows in order. when we select month, since its character, it showing from 'April, August....

but i want month prompt to start from Jan...

Any suggestion on how to modify..

thanks
Phanicrn

View 9 Replies View Related

How To Order In Month Column

Nov 15, 2007

hi,

table ab contain two column
no dispaymonth
1 April
2 jan
3 Mar

when i using order by in Month column it will return Alpha/- order(April,Mar,jun like that) but i need Jan,Feb,March order

need that Query

Advance thanks

View 3 Replies View Related

Transact SQL :: Order By Month

Apr 21, 2015

I am using below query i want to order it by month so that data is displayed like

Select (count(I.Colour)) as Litres,
DATEName(MONTH,ShipDate) as [Loaded Date] from InkData I
group by DATEName(MONTH,ShipDate)
order by DATEName(MONTH,ShipDate)

Right now it is not ordering by month, it is ordering alphabetically.I want this to be ordered like

Jan
Feb
March

View 6 Replies View Related

Pivot Table Month Name Order?

Dec 2, 2013

how to order by month name query returns Dec13,Mar14,Jan14,Nov13 .. etc but i want to Nov13,Dec13,Jan14,Mar14 ... etc

declare @cols as varchar(max),
@query as varchar(max)
set @cols =STUFF((select ','+QUOTENAME(tb3.month) FROM
( select distinct (DATENAME(MONTH,dtDate)+''+CONVERT(varchar(5),YEAR(dtDate)) ) as month
from tableA) tb3
FOR XML PATH(''), TYPE ).value('.','NVARCHAR(MAX)'),1,1,'')
set @query ='SELECT '+@cols +' from (SELECT DATENAME(MONTH,dtDate) + CONVERT(varchar(5),YEAR(dtDate)) as month,Price FROM tableA ) tb
pivot ( sum(Price) for monthin('+@Cols+')) p
'exec(@query)

View 6 Replies View Related

Sort By Year Order, Not By Month

Feb 27, 2008

When I sort the effective date, it sorts it in month order with all of the years together under that month.

Is it possible to sort the effective date in year order? The way it if formated right now is 01-01-2007. Is there any type of formula that I can use?

Below is the field that I use.
CONVERT(CHAR(10),pcsp.pcsp_eff , 110)

View 5 Replies View Related

Getting Year/quarter/month/day In The Right Order (was Dates)

Feb 28, 2005

I have a program that calls queries (OLAP system) the system includes a dimension of date: Year, Quater, Month, Week

When the result appears in the table, it is not in order? Only the year is in oredr and after that each heirachy is wrong and not in order....not sure how to do this!!!

any help would be grateful!!! not sure what I should be looking at.....

View 14 Replies View Related

SQL Server 2014 :: Order By Month Number In A Group By

Dec 19, 2014

Sample Data
SET NOCOUNT ON;
USE tempdb;
GO
CREATE TABLE CheckRegistry (
CheckNumber smallint,

[code]...

How can I get the result orderd by the month number?

View 3 Replies View Related

Reporting Services :: Change Order Of The Day Of Week Names In Parameter Drop Down List In SSRS?

Aug 26, 2015

I have a requirement to show Day of week in parameter drop down list in different order, actual order is Monday to Sunday (Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday) in DayOfWeek dimension in cube.

But my requirement is to show Friday to Thursday(Friday,Saturday,Sunday,Monday,Tuesday,Wednesday,Thursday) in DayOf Week parameter drop down list and report table. How I can get this requirement done.

View 2 Replies View Related

Parameter Selection Of Month, Showing Selected Month And Sum Up To That Month In Another Row

Apr 5, 2008

Hello what I'd like to display the following in a matrix report:

Parameter selected: 3 (March), 2008 (Year)

Monthly TO Summed up
ArtNo March <=March
1210 20,500 50,900
1220 21,200 64,000
1230 15,400 40,300
... ... ...

So, in the rows I have the articles and in the column the selected month via parameter. In another column I need to sum up all monthly values up to the selected month, meaning in this example the sum of jan, feb and mar per article.

View 3 Replies View Related

T-SQL (SS2K8) :: Get Last Record In A Month When No Guarantee Month Exists Of Unique Dates?

Apr 22, 2015

following table global_usage

ID varchar (contains alphanumeric values,not unique)
Territory (combined with ID unique)
Total_Used int can be null
Date_ date (date of the import of the data)
ID Territory Total_Used Date_
ACASC CAL071287 2014-06-01
ACASC CAL071287 2014-08-01
ACASC CAL071288 2014-09-01

[Code] .....

Now the problem,per month I need the most recent value so I'm expecting

ACASC CAL071287 2014-06-01
ACASC CAL071287 2014-08-01
ACASC CAL071288 2014-09-01
ACASC CAL071288 2014-11-01
ACASC CAL071190 2014-12-14
ACASC CAL071286 2015-01-22
ACASC CAL071165 2015-02-01
ACASC CAL071164 2015-03-01

I've tried a few thing like group,having even row_number() but I keep getting wrong results

View 6 Replies View Related

Transact SQL :: Show (0) Amount For A Month If No Data Exists In The Table For That Month?

Nov 9, 2015

I have two tables Costtable (Id,ResourceId, Amount,Date) and ResourceTable (ResourceId,Name) which shows output as below.

I want to show 0 amount for rest of the name in case of September. For e.g. if rest of the Resources does not appear in cost table they should appear 0 in amount

My Desired output

My current query

SELECT
RG.Id AS Id,
RG.Name AS Name,
ISNULL(SUM(AC.Amount), 0) AS Amount,
RIGHT(CONVERT(varchar(10), AC.[Date], 105), 7) AS [YearMonth]

[Code] ....

View 6 Replies View Related

T-SQL (SS2K8) :: Convert Number Of Month In Integer Into How Many Year And Month

Sep 10, 2014

This is my table and data

CVID | WorkExperience
--------------------------------
2838736
68181101
96568122
1135484

I need to convert into this result

CVID | WorkExperience
--------------------------------
283873 years
681818 years 5 months
9656812 years 2 months
1135484 months

View 5 Replies View Related

Transact SQL :: Displaying Sales Data In A Month By Month Grid

Aug 11, 2015

Most of the data is in one table. 

Company 1-Jan 1-Feb 1-Mar 1-Apr
RSP RSP RSP RSP
NON-RELO $295 1 $0 0 $1,400 7 $0 0 $1,195 4 $0 0 $4,700 8 $0 0
AMERICAN ESCROW & CL//AECC $2,650 4 $0 0 $3,720 8 $0 0 $2,339 4 $0 0 $2,460 2 $0 0
American Internation//AIRCO $9,131 30 $2,340 9 $10,927 35 $2,340 9 $9,142 31 $2,600 10 $18,406 54 $3,900 15
American Internation//AIR $20,611 63 $1,820 8 $23,892 75 $1,040 4 $35,038 111 $3,120 12 $3,778 16 $1,560 6
American Internation//Ab $64,248 206 $6,240 24 $59,800 187 $5,200 20 $87,115 264

I did something similar doing just record counts but this is far more complicated. I'm at a loss that this is even possible.

 SUM(CASE datepart(month, tbFile.openedDate) WHEN 1 THEN 1 ELSE 0 END) AS 'January', 

View 2 Replies View Related

Dynamically Pass Table Names And File Names To IS Package

Mar 1, 2015

I am designing a package to export staging tables into a flat file.The names of the tables will be: TableAStaging_YYYYMM and TableBStaging_YYYYMM. As you can see the names of the tables will be changing each month.

The flat files will have similar naming: C:MyPathFlatFileTableAStaging__YYYYMM and C:MyPathFlatFileTableAStaging__YYYYMM.I want to run the package as an sql job in two steps, one for each table.I need to dynamically pass the table names and file names (together with the path) to the IS package.

View 1 Replies View Related

Integration Services :: Chinese Names Export To CSV - Garbled Names

Aug 11, 2015

As part if a recent requirement I have to export Chinese/Singaporean names in a CSV file. The data in the tables is a NVARCHAR(256).

I am using a FlatFile Connection manager where all the present columns from the table are exported as NVARCHARs. My understanding was that the Chinese/Singaporean names would blend seamlessly with NVARCHARs in place. But, they get garbled when pushed to the CSV.

Here is the connection manager setup

There are a lot of suggestions of fixing this by copying/pasting to a notepad file and changing the formatting... But I cant do that since the file is generated using a schedules SSIS package. How can I tweak the process to fix the issue?

View 4 Replies View Related

Determine Table Names And Column Names At Runtime?

Jan 22, 2004

Hi

I was wondering if anyone has an idea of how we could find the table names and column names of the tables in our Sql server database at runtime/dynamically given our connection string? Please let me know.

Thanks.

View 5 Replies View Related

DB Mirroring: Different Server Names With Same Instance Names

Jan 31, 2008

I'm going to be setting up DB mirroring between two SQL Server 2005 boxes. Since these are on two different servers, can the instance names be the same? Is there any reason NOT to do so if the mirror server is going to be used exclusively for DB mirroring?

For example: if the my primary DB is located on SERVER1INSTANCE1, can the mirror be SERVER2INSTANCE1 or do the instance names have to be different even though they're on different boxes.

Thanks!

View 4 Replies View Related

Get Last Day Of Month For Agiven Month And Year

Aug 2, 2002

Does anyone know how I can get last day of month
if I pass a function a given month and and given year.
@Month = 2
@Year = 2004
The result I would need is 29 because there are 29 in
the month of February in the 2004.
Any help on this is greatly appreciated.
Kellie

View 1 Replies View Related

Table Names And Field Names

Jan 21, 2004

I'm trying to do an update query that looks like this:

UPDATE

PAEMPLOYEE

SET PAEMPLOYEE.LOCAT_CODE = EMPLOYEE.PROCESS_LEVEL


FROM

PAEMPLOYEE A

JOIN EMPLOYEE B ON A.EMPLOYEE = B.EMPLOYEE

It's erroring out on the Employee prefix B.EMPLOYEE saying:

..."does not match with a table name or alias name used in the query"


Is it wrong or will it cause problems to have a field name the same as the table name?

View 5 Replies View Related

Server Names Or Instance Names

Aug 3, 2006

Hello there. I'm trying to populate a drop down box with a list of all available instances of SQL server (express or not) available on a network. To list all instances I'm using EnumAvailableServers() in SmoApplication.

The issue is that the Instance column in the returned data table is always empty, and both the Name and the Server columns contain the same string -- the name of the computer the SQL server is installed. Locally I have SSE installed, the instance name is <computer_name>SQLEXPRESS, however, using Smo I can't seem to get to the either full instance name or just the instance name. I can't assume SQLEXPRESS, since there may be more than one installed.

Alternately I used EnumRegisteredServers() in SmoApplication.SqlServerRegistrations and that, while returning instance information (can be retrieved from the RegisteredServer in the returned collection), doesn't always return the remote SQL servers in the list.

Any idea how can this be done? Maybe I'm going at it the wrong way, maybe there's another class / method I need to use to retrieve all instances?

Thank you

View 6 Replies View Related

Ordering

Mar 3, 1999

Hi there!

We are experiencing a problem using order clause in the statement below:

SELECT
person.pkey
, first_name
FROM
person
, private_person
WHERE
fkey_person = person.pkey
AND first_name = 'A'
ORDER BY
first_name
, person.pkey

Where person table contains the following columns:

pkey, name etc

and private_person

pkey, fkey_person (indexed), first_name (indexed)

The output is:

STEP 1
The type of query is SELECT
FROM TABLE
private_person
Nested iteration
Index : i$private_person$first_name
FROM TABLE
person
Nested iteration
Using Clustered Index
pkey first_name
----------- ---------------------
2000512 A
10994 A
2299 A
1097 A
1218 A
5133 A
1329 A
1387 A
1465 A
7532 A
5513 A
1884 A
512 A
591 A

(14 row(s) affected)

STEP 1
The type of query is SETOFF

Why SQL server does not order by pkey? Is there any information about it somewhere? Is it a bug or what?

If we are ordering by fkey_person everything is Ok. Can anybody help?

Thanks a lot!

Kind Regards,
Vladimir

View 4 Replies View Related

Ordering Ids

Jun 18, 2007

I have a table named as C1_Messages with fields Id, Messages, Dates.
My Id filed looks like this:
1000
1001
1008
1009
1084
1093
1098 etc.

But here I need to make these Ids in a order, means it sould be in a consecutive order. Like
1000
1001
1002
1003
1004
1005 etc.

So is there anyway to do this method in SQL?

Regards
Shaji

View 5 Replies View Related

Express Will Not Load. Insurmountable Difficulties With Order Of Uninstalls/order Of Installs/ Suggestions Plz

Jan 7, 2007

Finding the "pieces of information" I need to successfully install the SQL Server Express edition is so complex. Uninstalls do "not" really uninstall completely, leading to failure of SQL install. Can you suggest a thorough, one-stop site for directions for the order of app uninstalls and then the order for app installs for the following...

SQL Server Express edition

Visual Studios 2005

Jet 4.0 newest upgrade

.Net Framework 2.0 (or should I use 3.0)

VS2005 Security upgrade

Anything else I need for just creating a database for my VS2005 Visual Basic project?

I was trying to use MS Access as my backend db but would like to try SQL Express



Thank you, Mark





View 7 Replies View Related

Conditional Order By - Sort Result Set By Employee Number Ascending Order

Sep 24, 2012

In SQL sERVER 2008, I have two fields - Depatment and Employees. I need to sort the result set by employee number ascending order, with following exception

1)when department number = 50 - the preferred order is Employee # - 573 followed by 551-572 (employee # belong to Dept 50 = 551-573)

2)When Department number = 20 – the preferred sort order is Employee # 213-220, followed by Employee # 201-213 (employee # belong to Dept 20 = 201-220)

How shall I achieve this?

View 4 Replies View Related

Analysis :: Order Of Rows In Tabular Table Not In Same Order Data Was Retrieved?

May 19, 2015

I never paid much attention to this before but I noticed this today in a new table I was creating.

For tables defined in the tabular model the table properties have something like SELECT Blah FROM TableName ORDER BY Blah Then in the tabular model the table's data is in the same order it was ordered by in the data source for the table.

I have a date table I setup and I noticed it is NOT respecting the sort order.

I have it sorted by DateID which sorts with the oldest date first and newest date as last row.However, the table that is imported and stored in the data model is not in that order.

I can of course manually sort the rows in BIDS/DataTools, but I find this discrepancy odd.

Would this have negative impacts on the EARLIER function for example if the data rows are not in the order specified?

View 8 Replies View Related

Calculate Total Amount Of Order Details Based On Particular Order

Apr 10, 2014

I have a query that calculate the total amount of order details based on a particular order:

Select a.OrderID,SUM(UnitPrice*Quantity-Discount)
From [Order Details]
Inner Join Orders a
On a.OrderID=[Order Details].OrderID
Group by a.OrderID

My question is what if I wanted to create a formula to something like:

UnitPrice * Quantity - DiscountAmount Where DiscountAmount = UnitPrice Quantity * Discount

Do I need to create a function for that? Also is it possible to have m y query as a table variable?

View 7 Replies View Related

Default Sort Order - Open Table - Select Without Order By

Mar 27, 2008

Hi!

I recently run into a senario when a procedure quiered a table without a order by clause. Luckily it retrived data in the prefered order.

The table returns the data in the same order in SQL Manager "Open Table"

So I started to wonder what deterimins the sort order when there is no order by clause ?

I researched this for a bit but found no straight answers. My table has no PK, but an identiy column.

Peace.

/P

View 5 Replies View Related

How To Add Order Item Into A Purchase Order Using A Stored Procedure/Trigger?

Jan 4, 2008

Hey guys, i need to find out how can i add order items under a Purchase Order number.
My table relationship is PurchaseOrder ->PurchaseOrderItem.

below is a Stored Procedure that i have wrote in creating a PO:



CREATE PROC spCreatePO (@SupplierID SmallInt, @date datetime, @POno SmallInt OUTPUT)

AS

BEGIN

INSERT INTO PurchaseOrder (PurchaseOrderDate, SupplierID) VALUES(@date, @SupplierID)

END



SET @POno = @@IDENTITY

RETURN


However, how do i make it that it will automatically adds item under the POno being gernerated? can i use a trigger so that whenever a Insert for PO is success, it automaticallys proceed to adding the items into the table PurcahseOrderItem?


CREATE TRIGGER trgInsertPOItem

ON PurchaseOrderItem

FOR INSERT

AS

BEGIN


'What do i entered???'
END

RETURN


help is needed asap! thanks!

View 14 Replies View Related

Ordering In The Table

Jun 27, 2006

Hello,
 
I have made sql table called costreallocation consists of two columsn:
RuleID varchar(10)
Type varchar(20)
I run the following three queries:
insert into costreallocation(RuleId,Type)values('aa','a')
insert into costreallocation(RuleId,Type)values('dd','d')
insert into costreallocation(RuleId,Type)values('cc','a')
then when i notice that these three records are not inserted as they are run:
In the table thn there are three records :
aa      a
cc      d
dd      d
but i need to be filled in the table as they run as:
aa      a
dd      d
cc      d
 
your help is highly appreciated
Best regards
 

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved