A Journey 2 Eternity

Create a Weekly Date Bucket

Posted by: Neel Aakash on: December 23, 2011


DECLARE @startdate SMALLDATETIME = '2011-01-01'
DECLARE @stopdate SMALLDATETIME = '2011-12-31'

-- Create a Table
DECLARE @weekTable TABLE (
Id INT IDENTITY (1, 1),
StartDate SMALLDATETIME,
EndDate SMALLDATETIME
)

-- Find Monday at that week
DECLARE @currentDate SMALLDATETIME = DATEADD(d, 2 - DATEPART(dw, @startdate), @startdate)

WHILE @currentDate <= @stopdate BEGIN
INSERT INTO @weekTable VALUES (@currentDate, DATEADD(d, 6, @currentDate))
SET @currentDate = DATEADD(ww, 1, @currentDate)
END

-- Return the results
SELECT Id 'Week #', StartDate 'Start Date', EndDate 'End Date'
FROM @weekTable

Tags: ,

“deprecated” in C++ Builder

Posted by: Neel Aakash on: November 23, 2011

We can deprecate a method, property, or even an entire class in C++ Builder, using the [[deprecated]] attribute. Deprecating an entity is a way of signalling to other developers that it should no longer be used, typically because there is another – more preferable – way of doing things.

When a deprecated entity is used in code, a compiler warning will be issued.

enum StatModelsType [[deprecated("Use StatisticalModelType instead.")]] {
smtNone = 0,
smtScanModel,
smtExFactoryModel,
smtOptimiserModel
};

Find the first date, last date and total days of a month

Posted by: Neel Aakash on: November 16, 2011


DECLARE @Date datetime
SET @Date = '2011/11/16'
SELECT  DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the week',
DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the week',
DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Total day of the month'

Tags: ,

Retrieving the table column details

Posted by: Neel Aakash on: November 16, 2011

The following query retrieving the table column details.

SELECT COLUMN_NAME [Field],DATA_TYPE + '(' + ISNULL(CONVERT(NVARCHAR,CHARACTER_MAXIMUM_LENGTH),'') + ')' + '    ' + CASE WHEN IS_NULLABLE = 'NO' THEN 'NOT ' ELSE '' END + 'NULL' [Type] 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'account' 
ORDER BY ORDINAL_POSITION ASC

Tags: ,

Painting a Gradient back ground

Posted by: Neel Aakash on: June 8, 2009

Here’s a sample which draws background of a dialog with gradient colors.

BOOL CMyDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);

TRIVERTEX vert[4] = {
{ rect.left, rect.top, 0xff00, 0xff00, 0xff00, 0 },
{ rect.right, rect.top, 0, 0xff00, 0xff00, 0 },
{ rect.right, rect.bottom, 0xff00, 0, 0xff00, 0 },
{ rect.left, rect.bottom, 0xff00, 0xff00, 0, 0 }
};

GRADIENT_TRIANGLE grad[2] = {
{ 0, 1, 2 },
{ 0, 2, 3 }
};

::GradientFill( pDC->m_hDC, vert, 4, grad, 2, GRADIENT_FILL_TRIANGLE );

return TRUE;
}

void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
// To ensure the background of the whole dialog is re-drawn
Invalidate();
CDialog::OnSize(nType, cx, cy);
}

Pages

Categories

 

February 2012
M T W T F S S
« Dec    
 12345
6789101112
13141516171819
20212223242526
272829  
Follow

Get every new post delivered to your Inbox.