Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Dense_rank function

Author  Topic 

Chaits
Starting Member

4 Posts

Posted - 2011-01-31 : 14:29:46
Hi Guys,

I am working on a code where Dense_rank function is used as follows.
SELECT DISTINCT
fiscal_year,
month1,
ES_WEEKOFYEAR,
TO_CHAR (ES_MONTH_END, 'YYYYMMDD') AS ES_MONTH_END,
DENSE_RANK () OVER (ORDER BY ES_MONTH_END) - 1 AS acctg_period_seq
FROM ps_es_dw_date
WHERE
TO_CHAR (ES_MONTH_END, 'YYYYMMDD') BETWEEN (&Curr_Mth_Start)
AND (&Curr_Mth_End)


Just FYI, variable (&Curr_Mth_Start) and (&Curr_Mth_End) are defined earlier as '20100702', 20100806' respectively.

I would like to know
a) what is the functionality and above exapmple usage of dense function.
b) What are the alternative of using dense function
c) what does a TO_CHAR function doing. I checked on Techonnet but it wont say anything about format 'YYYYMMDD'.

Thanks much.

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-31 : 15:10:56
TO_CHAR is not a SQL Server function, but it is similar to Excels TEXT function

Basically, it is TO_CHAR(string,format) . It is formatting the date into ISO standard format which is YYYYMMDD (4 digit year, 2 digit month, 2 digit day)





Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page
   

- Advertisement -