Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Receiving error message when trying to execute view in SQL 2005

Posted on 2010-08-13
7
Medium Priority
?
345 Views
Last Modified: 2012-06-21
Hello. I am not a SQL expert so I may be asking the wrong question. If anyone can point me in the right direction, it would be appreciated.

My environment is MS SQL 2005 SP3.

My company has a web page that is used for deploying software in SMS. I am setting up an environment for testing. I have the web page working correctly except for one item.

There is a tab on the web page that bring up settings based on AD site. One of the items used to display AD sites is a view (see code below). In production the LDAP looks at DC=FDS,DC=prd,DC=com'' I am only trying to change it to the lab values (DC=ent-test,DC=loc'').

When I make the change and execute I get the below error message.


Msg 468, Level 16, State 9, Procedure vComputerSettingsAllSites, Line 3
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

I have done research but cannot find a solution. Can anyone point me in the right direction?
USE [FDS_PNC]
GO
/****** Object:  View [dbo].[vComputerSettingsAllSites]    Script Date: 08/13/2010 20:55:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[vComputerSettingsAllSites]
AS
SELECT DISTINCT 
                      TOP (100) PERCENT CAST(SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255) AS nvarchar(50)) AS ADSite, 
                      CAST(cs.ADSiteDescription AS nvarchar(50)) AS ADSiteDescription, CAST(cs.NewComputerNamePrefix AS nvarchar(20)) AS NewComputerNamePrefix, 
                      CAST(cs.CaptureStateTo AS nvarchar(255)) AS CaptureStateTo, CAST(cs.DriverBasePath AS nvarchar(255)) AS DriverBasePath, 
                      CAST(cs.OSDLogShare AS nvarchar(255)) AS OSDLogShare, CAST(cs.BaseConfigShare AS nvarchar(255)) AS BaseConfigShare, 
                      CAST(CASE WHEN cs.TimeZoneID IS NULL THEN '-1' ELSE cs.TimeZoneID END AS nvarchar(3)) AS TimeZoneID, CAST(cs.JoinDomain AS nvarchar(50)) 
                      AS JoinDomain, CAST(cs.DestinationOU AS nvarchar(255)) AS DestinationOU, CAST(cs.JoinDomainUser AS nvarchar(50)) AS JoinDomainUser, 
                      CAST(cs.JoinDomainPass AS nvarchar(128)) AS JoinDomainPass, 
CAST(CASE WHEN cs.InputLanguageID1 IS NULL THEN '0000' ELSE cs.InputLanguageID1 END AS char(4)) AS InputLanguageID1,
CAST(CASE WHEN cs.KbdLayoutID1 IS NULL THEN '00000000' ELSE cs.KbdLayoutID1 END AS char(8)) AS KbdLayoutID1,
CAST(CASE WHEN cs.InputLanguageID2 IS NULL THEN '0000' ELSE cs.InputLanguageID2 END AS char(4)) AS InputLanguageID2,
CAST(CASE WHEN cs.KbdLayoutID2 IS NULL THEN '00000000' ELSE cs.KbdLayoutID2 END AS char(8)) AS KbdLayoutID2, CAST(CASE WHEN cs.StandardsFormatsID IS NULL 
                      THEN '00000000' ELSE cs.StandardsFormatsID END AS char(8)) AS StandardsFormatsID, CAST(CASE WHEN cs.LanguageID IS NULL 
                      THEN '0000' ELSE cs.LanguageID END AS char(4)) AS LanguageID, CAST(cs.LocalAdminPassword AS nvarchar(128)) AS LocalAdminPassword, 
                      CAST(CASE WHEN cs.LocalAdminPasswordIsEncrypted IS NULL THEN 0 ELSE cs.LocalAdminPasswordIsEncrypted END AS bit) 
                      AS LocalAdminPasswordIsEncrypted, CAST(cs.AdminGroupMember1 AS nvarchar(80)) AS AdminGroupMember1, 
                      CAST(cs.AdminGroupMember2 AS nvarchar(80)) AS AdminGroupMember2, CAST(cs.AdminGroupMember3 AS nvarchar(80)) AS AdminGroupMember3, 
                      CAST(cs.AdminGroupMember4 AS nvarchar(80)) AS AdminGroupMember4, CAST(cs.AdminGroupMember5 AS nvarchar(80)) 
                      AS AdminGroupMember5
FROM         OPENQUERY(ADSI, 'SELECT  siteObject
				  FROM ''LDAP://CN=Subnets,CN=Sites,CN=Configuration,DC=ent-test,DC=loc''
				  ') 
                      AS ad LEFT OUTER JOIN
                      dbo.ComputerSettingsForADSite AS cs ON cs.ADSite = SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255)
WHERE     (SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255) IS NOT NULL)

Open in new window

0
Comment
Question by:Lorrec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 33432698

USE [FDS_PNC]
GO
/****** Object:  View [dbo].[vComputerSettingsAllSites]    Script Date: 08/13/2010 20:55:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[vComputerSettingsAllSites]
AS
SELECT DISTINCT 
                      TOP (100) PERCENT CAST(SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255) AS nvarchar(50)) AS ADSite, 
                      CAST(cs.ADSiteDescription AS nvarchar(50)) AS ADSiteDescription, CAST(cs.NewComputerNamePrefix AS nvarchar(20)) AS NewComputerNamePrefix, 
                      CAST(cs.CaptureStateTo AS nvarchar(255)) AS CaptureStateTo, CAST(cs.DriverBasePath AS nvarchar(255)) AS DriverBasePath, 
                      CAST(cs.OSDLogShare AS nvarchar(255)) AS OSDLogShare, CAST(cs.BaseConfigShare AS nvarchar(255)) AS BaseConfigShare, 
                      CAST(CASE WHEN cs.TimeZoneID IS NULL THEN '-1' ELSE cs.TimeZoneID END AS nvarchar(3)) AS TimeZoneID, CAST(cs.JoinDomain AS nvarchar(50)) 
                      AS JoinDomain, CAST(cs.DestinationOU AS nvarchar(255)) AS DestinationOU, CAST(cs.JoinDomainUser AS nvarchar(50)) AS JoinDomainUser, 
                      CAST(cs.JoinDomainPass AS nvarchar(128)) AS JoinDomainPass, 
CAST(CASE WHEN cs.InputLanguageID1 IS NULL THEN '0000' ELSE cs.InputLanguageID1 END AS char(4)) AS InputLanguageID1,
CAST(CASE WHEN cs.KbdLayoutID1 IS NULL THEN '00000000' ELSE cs.KbdLayoutID1 END AS char(8)) AS KbdLayoutID1,
CAST(CASE WHEN cs.InputLanguageID2 IS NULL THEN '0000' ELSE cs.InputLanguageID2 END AS char(4)) AS InputLanguageID2,
CAST(CASE WHEN cs.KbdLayoutID2 IS NULL THEN '00000000' ELSE cs.KbdLayoutID2 END AS char(8)) AS KbdLayoutID2, CAST(CASE WHEN cs.StandardsFormatsID IS NULL 
                      THEN '00000000' ELSE cs.StandardsFormatsID END AS char(8)) AS StandardsFormatsID, CAST(CASE WHEN cs.LanguageID IS NULL 
                      THEN '0000' ELSE cs.LanguageID END AS char(4)) AS LanguageID, CAST(cs.LocalAdminPassword AS nvarchar(128)) AS LocalAdminPassword, 
                      CAST(CASE WHEN cs.LocalAdminPasswordIsEncrypted IS NULL THEN 0 ELSE cs.LocalAdminPasswordIsEncrypted END AS bit) 
                      AS LocalAdminPasswordIsEncrypted, CAST(cs.AdminGroupMember1 AS nvarchar(80)) AS AdminGroupMember1, 
                      CAST(cs.AdminGroupMember2 AS nvarchar(80)) AS AdminGroupMember2, CAST(cs.AdminGroupMember3 AS nvarchar(80)) AS AdminGroupMember3, 
                      CAST(cs.AdminGroupMember4 AS nvarchar(80)) AS AdminGroupMember4, CAST(cs.AdminGroupMember5 AS nvarchar(80)) 
                      AS AdminGroupMember5
FROM         OPENQUERY(ADSI, 'SELECT  siteObject
				  FROM ''LDAP://CN=Subnets,CN=Sites,CN=Configuration,DC=ent-test,DC=loc''
				  ') 
                      AS ad LEFT OUTER JOIN
                      dbo.ComputerSettingsForADSite AS cs ON cs.ADSite collate database_default = SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255)
WHERE     (SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255) IS NOT NULL)

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33432704
It has happened because your database was restored/attached between SQL servers with different collations.
0
 
LVL 16

Expert Comment

by:vdr1620
ID: 33432736
as the error says they both have different collations.. so you will need to convert the Table on SQL server to Latin_general_CI_AS Collation.. check the sample Code

select *
  from table_1
    inner join table_2
      on (table_1.field collate SQL_Latin1_General_CP850_CI_AI = table_2.field)
  where CONDITION

Also, i would suggest using fields with functions always on the left side of the operator

dbo.ComputerSettingsForADSite AS cs ON (SUBSTRING(LEFT(ad.siteObject, CHARINDEX(',', ad.siteObject) - 1), 4, 255) = cs.ADSite collate Latin1_General_CI_AS)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:almander
ID: 33432738
CyberKiwi has the right idea.

It is probably because the collation settings for the items/servers do not match. You could compare the collation on the two database servers, and would probably find that they do not match. If they do, it could be at the table/column level.
0
 

Author Comment

by:Lorrec
ID: 33432908
Wow. Thank you for the information and quick response.
0
 

Author Closing Comment

by:Lorrec
ID: 33432916
Thank you for the information and quick response.
0
 
LVL 12

Expert Comment

by:NormanMaina
ID: 33433055
what is your domain name?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question