Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 17-Apr-13 20:54pm
v2
Comments
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?
Joezer BH 18-Apr-13 3:08am    
What kind of table? HTML Table? C# Datatable? Database Table?

1 solution

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

SQL
;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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900