13,148,427 members (60,933 online)
Rate this:
See more:
Hi
I want to create a Table dynamically according to the Values
I want to show a table

from April Month to March
April  --
May    --
June   --
July   --
August --
Sept --
Oct --
Nov --
Dec --
Jan --
Feb --
March --
having two columns one for Month Names and other for Values
Values are calculated on a Formula:
1200/12 for April<br />
1200/11 for May<br />
and like wise divided by descending values and to show them accordingly against the Month Names.
How can I acheive this Please assist
Posted 17-Apr-13 20:28pm
Updated 17-Apr-13 20:54pm
Maciej Los255.6K
v2
Thomas Barbare 18-Apr-13 2:34am

What kind of db do you use ?
OriginalGriff 18-Apr-13 2:34am

What have you tried?
Where are you stuck?
Edo Tzumer 18-Apr-13 3:08am

What kind of table? HTML Table? C# Datatable? Database Table?

Rate this:

## Solution 1

If you use MS SQL Server, i recommend you to use CTE[^]:

;WITH MyColumns
AS
(
SELECT GETDATE() AS CurrMonth, '1200/' AS FirstPart , 12 AS SecondPart
UNION ALL
SELECT DATEADD(mm,1, CurrMonth), FirstPart, SecondPart -1 AS SecondPart
FROM MyColumns
WHERE SecondPart>1
)
SELECT DATENAME(mm, CurrMonth) AS Col1, FirstPart + CASE WHEN LEN(SecondPart)=2 THEN CAST(SecondPart AS NVARCHAR(2)) ELSE '0' + CAST(SecondPart AS NVARCHAR(2)) END AS Col2
FROM MyCOlumns

Result:
April		1200/12
May		1200/11
June		1200/10
July		1200/09
August		1200/08
September	1200/07
October		1200/06
November	1200/05
December	1200/04
January		1200/03
February	1200/02
March		1200/01

Top Experts
Last 24hrsThis month
 OriginalGriff 243 Kornfeld Eliyahu Peter 180 ppolymorphe 70 Dave Kreskowiak 70 Michael Freidgeim 54
 OriginalGriff 6,383 Graeme_Grant 5,101 ppolymorphe 2,064 Jochen Arndt 1,904 CPallini 1,855