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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to execute sql 2008 r2 CTE script in VBscript - 2nd select statement is not being executed

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Trying to excute a SQL 2008 r2 CTE script in VBscript - 2nd select statement is not being executed

The 1st select statment is being executed and is returning results

" select affiliationid as affiliationidq from Data " &_
" where Rownumberofaffiliates = 1 "



strConnection = "DRIVER=SQL Server;SERVER=ABN-NHP-SQL-T01,11001;UID=keithg;APP=QuickTest Professional;WSID=KEITHGJ790;DATABASE=Plandata_nhptest;Trusted_Connection=Yes"


Set conn = CreateObject("ADODB.Connection")

conn.Open strConnection

query =" ; With Data As " &_
"( " &_
"select " &_
" Row_Number() Over(Partition by a.provid order by g.fullname) as Rownumberofaffiliates " &_
" , a.affiliationid " &_
" , a.effdate " &_
", a.termdate " &_
", g. fullname as site " &_
" from dbo.affiliation a " &_
" left outer join provider g (nolock) on a.affiliateid = g.provid " &_
"WHERE a.provid = '" & DataTable.Value ("Provider_ID", dtGlobalSheet) &"'" &_
" and a.affiltype in ('GROUP', 'DIRECT') " &_
" ) " &_
" select affiliationid as affiliationidq from Data " &_
" where Rownumberofaffiliates = 1 "

Set rs2 = conn.Execute(query)

print query

AffiliationID=rs2("affiliationidq")



print "AffiliationID"
print AffiliationID
 
hi,

I would assign the second sql to a variable and then inspect the contents of the variable via debug.print. Use THAT string to access the data to check that it actually works.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top