k=conn:query({live=true,sql ="select DISTINCT O.OrderId, (SELECT R.ReportBody + (char(13)+char(10)) + 'Modified By: ' + UM.FirstName + ' at ' + UM.LastName + (char(13)+char(10)) +'Authored By: ' + UC.FirstName + ' at ' + UC.LastName + (char(13)+char(10)) + (char(13)+char(10)) AS [text()] FROM dbo.OrderReports R INNER JOIN dbo.Users UM ON R.ModifiedById = UM.UserId INNER JOIN dbo.Users UC ON R.CreatedById = UC.UserId WHERE R.OrderId = M[1].OrderId ORDER BY R.CreateDate DESC FOR XML PATH('')) 'OrderReport'FROM dbo.Orders O "})
我有上面提到的查询,我在where R.OrderId = M[1].OrderId
得到错误的语法错误,我正在使用带Lua的sql。
P.S:M [1]中的值.OrderId是唯一标识符。
但如果我有这个问题:
mk = conn:query({live = true, sql= "select ReportBody,DENSE_RANK() over (Order by ModifyDate DESC) from OrderReports where OrderId = '"..M[1].OrderId.."'"})
它适用于M [1] .OrderId虽然M [1] .OrderId在第一个查询中给出了语法错误。如何在第一次查询中修复此问题?
答案 0 :(得分:1)
好的,你还没有回答我的上一个问题。但假设您编写的查询正在运行,那么您就是这样:
k=conn:query({live=true,sql ="select DISTINCT O.OrderId, (SELECT R.ReportBody + (char(13)+char(10)) + 'Modified By: ' + UM.FirstName + ' at ' + UM.LastName + (char(13)+char(10)) +'Authored By: ' + UC.FirstName + ' at ' + UC.LastName + (char(13)+char(10)) + (char(13)+char(10)) AS [text()] FROM dbo.OrderReports R INNER JOIN dbo.Users UM ON R.ModifiedById = UM.UserId INNER JOIN dbo.Users UC ON R.CreatedById = UC.UserId WHERE R.OrderId = '"..M[1].OrderId.."' ORDER BY R.CreateDate DESC FOR XML PATH('')) 'OrderReport'FROM dbo.Orders O "})