Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server TSQL将行分隔为后续操作行_Sql Server_Tsql - Fatal编程技术网

Sql server TSQL将行分隔为后续操作行

Sql server TSQL将行分隔为后续操作行,sql-server,tsql,Sql Server,Tsql,我试图将按顺序发生的后续操作分为几列,第一个操作、第二个操作、第三个操作。我想我可以使用SyncDate来分割后续操作,但我不知道最好的方法 我已经使用row_number函数打成平局,但这并没有正确列出RowNo。我在考虑用CTE来分割这三个动作 这就是我目前所拥有的 SELECT [RM-JOB].[Job-No] [Visit no] , cast(ard.SyncDate as date) [SyncDate] , ard.actionref , ard.FollowUpReq [F

我试图将按顺序发生的后续操作分为几列,第一个操作、第二个操作、第三个操作。我想我可以使用SyncDate来分割后续操作,但我不知道最好的方法

我已经使用row_number函数打成平局,但这并没有正确列出RowNo。我在考虑用CTE来分割这三个动作

这就是我目前所拥有的

SELECT  [RM-JOB].[Job-No] [Visit no]

, cast(ard.SyncDate as date) [SyncDate]
, ard.actionref
, ard.FollowUpReq [FOLLOW ON]
, ARD.GeneralComments [FOLLOW ON ACTION]
, ROW_NUMBER()over(partition by [RM-JOB].[Job-No], cast(ard.SyncDate as date), ard.actionref order by ard.actionref, cast(ard.SyncDate as date) desc) AS 'RowNo'
FROM            [CYHSQL01].[TM_FireRiskAssessment].[dbo].[ActionRequiredDetails] ARD right outer JOIN
                [CYHSQL01].[TM_FireRiskAssessment].[dbo].ActionRequired AR ON ARD.ResultId = AR.ResultId inner join
                         [RM-JOB] on AR.JobNo = [RM-JOB].[Job-No]
这就产生了下面的结果,下面的数据也可以被视为数据

Visit no    SyncDate    actionref   FOLLOW ON   FOLLOW ON ACTION    RowNo
10233639    NULL    NULL    NULL    NULL    1
10233639    NULL    NULL    NULL    NULL    1
10233639    03/10/2019  CP31    No  Have visited all properties. All properties look to be compliant.   1
10233639    03/10/2019  CP31    No  Have visited all properties. All properties look to be compliant.   1
10233639    03/10/2019  CP33    Yes I’m not sure whether roof space is fire resistant. I will arrange for someone to inspect this.  1
10233639    04/10/2019  CP33    Yes I’m not sure whether roof space is fire resistant. I will arrange for someone to inspect this.  2
10233639    04/10/2019  CP33    No  Roofs Ltd will attend on 12/10/19   2
10233649    03/10/2019  CP31    No  All doors are fire compliant.   1
10233649    03/10/2019  CP31    No  All doors are fire compliant.   1
10233649    04/10/2019  CP33    Yes I will arrange for a contractor to carry out the inspection.    2
10233649    04/10/2019  CP33    No  I’ve arranged an appointment with the contractor to attend on 23/10/19  2
10233649    05/10/2019  CP33    Yes I will arrange for a contractor to carry out the inspection.    3
10233649    05/10/2019  CP33    No  I’ve arranged an appointment with the contractor to attend on 23/10/19  3
10233652    04/10/2019  CB8 No  Cardboard box was empty so I removed it from the communal area. 1
10233652    04/10/2019  CB8 No  Cardboard box was empty so I removed it from the communal area. 1
10233652    04/10/2019  CB8 No  Cardboard box was empty so I removed it from the communal area. 1
10233652    05/10/2019  CP32    No  All doors were checked and are fire resistant.  2
10233652    05/10/2019  CP32    No  All doors were checked and are fire resistant.  2
10233652    05/10/2019  CP32    No  All doors were checked and are fire resistant.  2
10233652    06/10/2019  CP33    Yes I will arrange for a contractor to inspect this.    3
10233652    06/10/2019  CP33    No  Contractor has been booked and will attend on 20/10/19  3
10233652    06/10/2019  CP33    Yes I will arrange for a contractor to inspect this.    3
10233652    06/10/2019  CP33    No  Contractor has been booked and will attend on 20/10/19  3
有人知道怎么做吗


谢谢你的帮助

向我们展示您失败尝试后的数据并不能真正帮助我们。我们需要知道您的数据在尝试之前是什么样子的,以及您希望最终的结果是什么样子的。请花时间格式化您的数据;我们拥有的数据非常混乱,我们不需要猜测每个值属于哪一列。您最好提供与DDL和DML语句相同的数据;但是,对于预期的结果,可读的表格格式的
text
就可以了。谢谢Larnu,我不知道如何格式化数据。除了行数之外的数据就是它的状态。