无法解决“SQL_Latin1_General_CP1_CI_AS”之间的排序规则冲突

时间:2014-02-17 09:08:09

标签: sql-server tsql collate

我执行该语句时有一个动态sql语句然后我收到错误无法解决“SQL_Latin1_General_CP1_CI_AS”之间的排序规则冲突

我使用COLLATE SQL_Latin1_General_CP1_CI_AS or COLLATE DATABASE_DEFAULT但仍然出现错误

这是我的sql snap

ALTER PROC SearchByJID  
(  
 @JID    VARCHAR(max),  
 @TrackNo   VARCHAR(max),  
 @PageSize        INT,                      
 @PageNumber      INT    
)  
AS  

DECLARE @SQL VARCHAR(MAX)         
DECLARE @Count_SQL VARCHAR(MAX)                    
DECLARE @RowStart INT                      
DECLARE @RowEnd INT                      

SET @PageNumber = @PageNumber - 1                      
SET @RowStart = @PageSize * @PageNumber + 1                      
SET @RowEnd = @RowStart + @PageSize - 1                      
SET @SQL=''          
SET @Count_SQL=''                   


 BEGIN        
   SET @SQL='SELECT * FROM  (SELECT Row_number() OVER (ORDER BY [bbajobs].JID ) AS RowNumber,                      
   [BBAJobs].[JID],[AccountReference] as [Acc Ref],[BBAJobs].[OEReference] as [OERef],[JobType],[JobState],  
   [JobShippedDate],[UPSShippingNumber],[CustomerName] [Customer Name],[ContactName] [Contact Name],[Telephone],  
   [JobDescription],[CallRem].[rem],[CallRem].[callStatus],[CallRem].[ShopRemarks],  
   CustomerNotes,ShopNotes,RecievedDate,UserName FROM dbo.BBAJobs LEFT OUTER JOIN dbo.CallRem   
   ON dbo.BBAJobs.JID = dbo.CallRem.jid WHERE 1<2 '  

   IF @TrackNo <> ''  
   BEGIN                    
    SET @SQL=@SQL+' AND [bbajobs].jid IN (select jid from trackdetail WHERE TRACKNO IN(  
    SELECT CONVERT(VARCHAR, data) AS [JID]                     
    FROM dbo.Split1('''+@TrackNo+''', '','')))'        
   END  

   IF ltrim(rtrim(@JID)) <> ''                    
   BEGIN                    
    SET @SQL=@SQL+' AND [bbajobs].jid IN (SELECT CONVERT(VARCHAR, data) AS [JID]                     
    FROM dbo.Split1('''+@JID+''', '','')) '        
   END  

   SET @SQL=@SQL+') x WHERE RowNumber BETWEEN '+CAST(@RowStart AS VARCHAR)+' AND '+CAST(@RowEnd AS VARCHAR)              

-- Get Count  
   SET @Count_SQL= 'SELECT COUNT(bbajobs.[JID]) FROM dbo.BBAJobs LEFT OUTER JOIN dbo.CallRem   
   ON dbo.BBAJobs.JID = dbo.CallRem.jid WHERE 1<2 '  

   IF @TrackNo <> ''  
   BEGIN                    
    SET @Count_SQL=@Count_SQL+' AND bbajobs.jid IN (select jid from trackdetail WHERE TRACKNO IN(  
    SELECT CONVERT(VARCHAR, data) AS [JID]                     
    FROM dbo.Split1('''+@TrackNo+''', '','')))'        
   END  

   IF ltrim(rtrim(@JID)) <> ''                    
   BEGIN                    
    SET @Count_SQL=@Count_SQL+' AND bbajobs.jid IN (SELECT CONVERT(VARCHAR, data) AS [JID]                     
    FROM dbo.Split1('''+@JID+''', '',''))'                     
   END  
 END  

exec(@SQL+@Count_SQL)  

特别是当我发送曲目编号时我收到错误,所以我猜这里是错误的谎言

IF @TrackNo <> ''  
   BEGIN                    
    SET @SQL=@SQL+' AND [bbajobs].jid IN (select jid from trackdetail WHERE TRACKNO IN(  
    SELECT CONVERT(VARCHAR, data) AS [JID]                     
    FROM dbo.Split1('''+@TrackNo+''', '','')))'        
   END  

所以请指导我在sql中修改什么来解决这个问题。

我这样做了&amp;解决了这个问题

   IF @TrackNo <> ''  
   BEGIN                    
    SET @SQL=@SQL+' AND [bbajobs].jid IN (select jid from trackdetail 
    WHERE TRACKNO COLLATE DATABASE_DEFAULT IN(  
    SELECT data COLLATE DATABASE_DEFAULT AS [JID]                      
    FROM dbo.Split1('''+@TrackNo+''', '','')))'       
   END  

1 个答案:

答案 0 :(得分:1)

尝试

SET @SQL=@SQL+' AND [bbajobs].jid IN (select jid from trackdetail WHERE 
TRACKNO collate database_default IN(  
SELECT CONVERT(VARCHAR, data) AS [JID] collate database_default                     
FROM dbo.Split1('''+@TrackNo+''', '','')))'