在C#或VB.NET中动态创建表 [英] create a Table dynamically in C# or VB.NET
本文介绍了在C#或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<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
推荐答案
如果您使用MS SQL Server,我建议您使用 CTE [ ^ ]:
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
这篇关于在C#或VB.NET中动态创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文