Single Quote Conversions

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!
LVL 9
nito8300Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

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
 
nito8300Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.