Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET VB.NET
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
1200/11 for May
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 21:28pm
Edited 17-Apr-13 21:54pm
Maciej Los150.9K
v2
Comments
Thomas Barbare at 18-Apr-13 2:34am
   
What kind of db do you use ?
OriginalGriff at 18-Apr-13 2:34am
   
What have you tried?
Where are you stuck?
Edo Tzumer at 18-Apr-13 3:08am
   
What kind of table? HTML Table? C# Datatable? Database Table?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100