0

我的存储过程中有 T-SQL 语句,这给了我错误。但是相同的查询在查询窗口中运行得很好。它给出了错误说

'.' 附近的语法不正确

Set @SQL='Select ''<a href="javascript:editTicketByIDAction('' + 
          CONVERT(VarChar(Max), Ticket) + '')">'' + 
          CONVERT(VarChar(Max),t1.Ticket) + 
          ''</a>'' t1.Ticket,VendorTicket[Vendor Ticket], Comments 
From VendorTickets t1 
WHERE NotifyOn <= GetDate() And NotifyOn Is Not Null AND 
NOT EXISTS(SELECT * FROM VendorTickets t2 
WHERE t1.Ticket = t2.Ticket AND t1.InitiatedOn < t2.InitiatedOn)'

Exec(@SQL)

没有 T-SQL 它运行良好

    SELECT t1.Ticket,t1.VendorTicket,t1.Comments 
FROM VendorTickets t1 WHERE 
NOT EXISTS(SELECT * FROM VendorTickets t2 
WHERE t1.Ticket = t2.Ticket AND t1.InitiatedOn < t2.InitiatedOn)
AND  NotifyOn <= GetDate() And NotifyOn Is Not Null
4

2 回答 2

6

你错过了一个+

... + '</a>' +  t1.Ticket ...
             ^------------------------here
于 2012-08-13T10:39:44.270 回答
0

你错过+了两个地方。试试这个:

Set @SQL='Select + ''<a href="javascript:editTicketByIDAction('' + 
          CONVERT(VarChar(Max), Ticket) + '')">'' + 
          CONVERT(VarChar(Max),t1.Ticket) + 
          ''</a>'' + t1.Ticket,VendorTicket[Vendor Ticket], Comments 
From VendorTickets t1 
WHERE NotifyOn <= GetDate() And NotifyOn Is Not Null AND 
NOT EXISTS(SELECT * FROM VendorTickets t2 
WHERE t1.Ticket = t2.Ticket AND t1.InitiatedOn < t2.InitiatedOn)'

Exec(@SQL)
于 2012-08-13T10:59:01.643 回答