Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Single Quote Conversions

Posted on 2006-04-24
3
Medium Priority
?
402 Views
Last Modified: 2006-11-18
Hello,
Can anyone help me out converting the statement below? I'm having trouble with single quotes...

from:
SELECT * FROM OpenQuery( ADSI, 'SELECT name, adsPath FROM
''LDAP://DC=mydomain,DC=com'' WHERE objectCategory = ''Person'' AND objectClass= ''user''')

to:

declare @var1 varchar(255)
declare @sql varchar(8000)

set @var1 = select domain from domainLookup
-- var1 would equal to:   DC=mydomain,DC=com

@sql = 'SELECT * FROM OpenQuery( ADSI, 'SELECT name, adsPath FROM
''LDAP://' + @var1+ ' WHERE objectCategory = ''Person'' AND objectClass= ''user''') '

exec (@sql)

thank you all!
0
Comment
Question by:nito8300
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16529140

declare @var1 varchar(255)
declare @sql varchar(8000)

set @var1 = select domain from domainLookup
-- var1 would equal to:   DC=mydomain,DC=com

@sql = 'SELECT * FROM OpenQuery( ADSI, ''SELECT name, adsPath FROM
''''LDAP://' + @var1+ ' WHERE objectCategory = ''''Person'''' AND objectClass= ''''user'''' '') '

exec (@sql)
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16529149
to explain: you have to make the duplicate in theOpenQuery 2 times, one for the string in the OpenQuery, and once for the @sql variable delimiter.
0
 
LVL 9

Author Comment

by:nito8300
ID: 16529246
thanks that got me close enough to figure it out

set @sql = 'SELECT * FROM OpenQuery( ADSI, ''SELECT name, adsPath,sAMAccountName,whenChanged FROM
''''LDAP://' + @var1+ ''''' WHERE objectCategory = ''''Person'''' AND objectClass= ''''user'''' '') '
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

810 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