The SET @ the MONTH='2019'
DECLARE @ SQL VARCHAR (8000)
The SET @ SQL='SELECT T2. * FROM Operation_User T1 LEFT JOIN (SELECT ClerkName'
SELECT SQL + SQL=@ @ ', the sum (case when datepart (dd, CreatedDate)='+ CAST (number AS VARCHAR (2)) +' then Workinghours else null end) [' + CAST (number AS VARCHAR (2)) + '] '
FROM the master.. Spt_values WHERE type='P' AND number> 0 AND number<=DAY (DATEADD (DAY 1, DATEADD (1 MONTH, @ the MONTH)))
SQL=SET @ @ + SQL ', ISNULL (SUM (Workinghours), 0)/total working hours'
SQL=SET @ @ + SQL 'FROM Clickfarmingtable'
+ 'WHERE Machinetype<> "' 2 'AND CreatedDate>="' + CONVERT (VARCHAR (10), @ the MONTH, 120) + ' ' 'AND CreatedDate<"' + CONVERT (VARCHAR (10), DATEADD (1 MONTH, @ the MONTH), 120)
+ "' GROUP BY ClerkName) T2 ON T1. RealName=T2. ClerkName '
SQL=SET @ @ SQL
The EXEC (@ SQL)
Below are the results to check

Hope turn line column with the following format the results
Date Yang Qijin QinWenYou Liang Chengsong YuYangLun shu small even
1
38.002, 26.11
3
4
5
6
7
8
9
10
11.
CodePudding user response:
To the results of the dynamic SQL execution on the temporary table, then query a temporary table row column,CodePudding user response:
https://www.cnblogs.com/lhj588/p/3315876.htmlLook at the
CodePudding user response:
[color=# FFFF00] [/color]