Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of OPENDATASOURCE and NOLOCK

Status
Not open for further replies.

glthornton

Programmer
Oct 19, 2005
108
US
Hi everyone,
Configuration: MS SQL 2000 using Server 2003. I am trying to design a query that will allow me to access different databases using the OPENDATASOURCE command but also using the WITH (NOLOCK) command as well. I know that using NOLOCK is using a 'dirty read', but it's okay with what I'm doing. My query looks like this:

Code:
SELECT DISTINCT PatID
FROM OPENDATASOURCE('SQLOLEDB','Data Source=VTMAIM;User ID=pcadmin;Password=letmein').scandb.dbo.ScanDocs WITH (NOLOCK)
WHERE DocType = 'Consults - Eye' and ScanDate >= DateAdd(day, DateDiff(Day, 0, GetDate()-1), 0) AND ScanDate < DateAdd(day, DateDiff(Day, 0, GetDate()), 0)

When I try and check/parse the query in query analyzer, I get an error stating: 'incorrect syntax near the keyword WITH'.

I want to use both commands, but it does not seem to be working. Does anyone have any suggestions?

Glenn
 
You can't use lock hints with opendatasource. You can however use openquery if it's a sql server your connecting to.

Something like:
Code:
SELECT *
FROM OPENQUERY(SELECT DISTINCT PatID FROM scandb.dbo.ScanDocs WITH (NOLOCK)
WHERE DocType = 'Consults - Eye' and ScanDate >= DateAdd(day, DateDiff(Day, 0, GetDate()-1), 0) AND ScanDate < DateAdd(day, DateDiff(Day, 0, GetDate()), 0))

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top