sql 获取某一月份内所有日期 作为列名

sql 获取某一月份内所有日期 作为列名,第1张

需要写存储过程拼sql。

create proc P

@YearMonth varchar(6) --年月

as

begin

Declare @SDate DateTime-本月第一天

Declare @EDate DateTime--本月最后一天

Declare @SumDate int --总天数

Declare @i int

Set @SDate=CAST(@YearMonth+'01' AS Datetime)

--在本月第一天的基础上加1个月 然后减一天 就是本月最后一天

Set @EDate=DateAdd(M,1,@SDate)-1

--计算出差一天数

Set @SumDate=DATEDIFF(D,@SDate,@EDate)

set @i = 0

while @i<@SumDate

begin

--凑sql 我就不写详细了 列名就是 @SDate+i

end

end

  SqlConnection thisConnection = new SqlConnection(ConfigurationManagerAppSettings["ConnectionString"]ToString());

            // Open connection

            thisConnectionOpen();

            // Create command for this connection

            SqlCommand thisCommand = thisConnectionCreateCommand();

            // Specify SQL query for this command

            thisCommandCommandText = sCommandText;

            // Execute DataReader for specified command

            SqlDataReader thisReader = thisCommandExecuteReader();

            // While there are rows to read

            //

            //

            View_LogDetailEntity = new List<CView_LogDetail>();//初始化集合

 string sColumnName = stringEmpty;

  while (thisReaderRead())

            {

                CView_LogDetail myCView_LogDetail = new CView_LogDetail();

                for (int i = 0; i < thisReaderFieldCount; i++)

                {

                      sColumnName = thisReaderGetName(i)Trim();

                }

           }

以上就是关于sql 获取某一月份内所有日期 作为列名全部的内容,包括:sql 获取某一月份内所有日期 作为列名、C# 中SqlDataReader怎么获取列名、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9734785.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存