Re: Sorting results by year and date
From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 04/18/04
- Previous message: wantjoule_at_ncl.com: "Sorting results by year and date"
- In reply to: wantjoule_at_ncl.com: "Sorting results by year and date"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 18 Apr 2004 14:44:41 +0530
hi willa,
What is happening is, because of "group by" clause on "sail_dat" column each
distinct value of SAIL_DAT is retrieved , therefore values like 1 apr 2004,2
apr 2004 are also retrieved. and while , viewing them you are retrieving
only year and month out of it. So you think values are getting repeated. you
can test this by writing following query.
SELECT
DATENAME(day,SAIL_DAT) AS 'day', --check the day.
DATENAME(YEAR,SAIL_DAT) AS SAIL_YEAR,
DATENAME(MONTH,SAIL_DAT) AS SAIL_MONTH
FROM dbo.IPS_POINTS
GROUP BY DATENAME(YEAR,SAIL_DAT),DATENAME
(MONTH,SAIL_DAT),SAIL_DAT
ORDER BY SAIL_DAT
you can correct your query as follows:
select sail_year, sail_month
from
(SELECT DATENAME(YEAR,SAIL_DAT) AS SAIL_YEAR,
DATENAME(MONTH,SAIL_DAT) AS SAIL_MONTH,
right('0' + cast(month(sail_dat) as varchar(2)),2) 'mnth'
FROM
IPS_POINTS WHERE RES_AGENT_CD = 'PLUMB_N'
GROUP BY DATENAME(YEAR,SAIL_DAT),DATENAME(MONTH,SAIL_DAT),
right('0' + cast(month(sail_dat) as varchar(2)),2)) X
ORDER BY cast(SAIL_YEAR + mnth + '01' as datetime)
-- Vishal Parkar vgparkar@yahoo.co.in
- Previous message: wantjoule_at_ncl.com: "Sorting results by year and date"
- In reply to: wantjoule_at_ncl.com: "Sorting results by year and date"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
- Re: New "base document" available
... be done about retrieving command line parameters. ... System) which was for
passing messages, control, and data between the ... new forms of Query Expression
which are "SQL-like" but far removed from SQL ... (comp.lang.cobol) - Re: Datagrid hide identical columns from a JOIN
... There are a couple of other issues with not retrieving your primary ... >
Why don't you write your query to return only the fields that you need ... > let's say
you have SalesId in sales table and SalesId in salesdetails ... > join salesdetails
on sales.salesid = salesdetails.salesid ... (microsoft.public.dotnet.framework.adonet) - Re: Datagrid hide identical columns from a JOIN
... There are a couple of other issues with not retrieving your primary ... >
Why don't you write your query to return only the fields that you need ... > let's say
you have SalesId in sales table and SalesId in salesdetails ... > join salesdetails
on sales.salesid = salesdetails.salesid ... (microsoft.public.dotnet.framework.windowsforms.controls) - Re: Website Run By Offsets Query
... It would be just one database query to get the ... which I suppose would be
the same as retrieving through a key value. ... When I do the query on a indexed
key field value then the query to the ... (comp.lang.php) - Numeric to string problems.
... settings (South America). ... In some part of the code, i'm retrieving
values ... the "," is completely messing up the query. ... (microsoft.public.dotnet.languages.vb)