2012-12-05 116 views
1

我有這個VB腳本正在第三方應用程序中運行,並且正在拋出「期望的語句結束」錯誤,下面是有問題的代碼:SELECT語句在SQL服務器管理器中正常工作工作室。聲明錯誤的預期結束

感謝。

Dim SecurityDB 
Set SecurityDB = CreateObject("ADODB.Connection") 
Conn = "DRIVER={SQL Server};SERVER=ustcca015s6\Continuum;DATABASE=continuumdb;UID=Andy8796;PWD=xxxx1234;" 
SecurityDB.Open Conn 
Set EmployeeRS = SecurityDB.Execute "Select count(*) from dbo.personnel where state=1 and lastname not like 'lapt%' and lastname is not NULL and valuelo in (Select ObjectIdLo from area where uiname like 'usmm%' and uiname not like '%gate%') and valuelo <> 1111497912;" 
Result = EmployeeRS.GetRows 
EmployeeRS.Close 
SecurityDB.Close 
+5

執行後不需要括號嗎? 'Set EmployeeRS = SecurityDB.Execute(「Select count(*)from dbo.personnel where state = 1 and lastname not like'lapt%'and lastname is not NULL and valuelo in(從使用uiname的地方選擇ObjectIdLo'usmm%'和uiname不喜歡'%gate%')和valuelo <> 1111497912;「)' – RichardTheKiwi

+0

@RichardTheKiwi的評論是正確的:只有一個'sub'(不返回返回值的例程)可以在沒有括號的情況下被調用。如果你正在調用'function',那麼括號是強制性的。查看'MsgBox「進程終止,」vbOKOnly「和'answer = MsgBox(」你想終止進程嗎?「,vbYesNo)之間的區別' – AutomatedChaos

+1

@RichardTheKiwi:爲什麼不作爲回答發佈? – Helen

回答

1

@RichardTheKiwi張貼在評論部分兩週前的答案,但遺憾的是並沒有增加它作爲......答案部分。OK,點皮條客回答[ette]今天晚上回來,所以這些問題顯示爲離「解決」更近一步!

執行後你不需要一個括號嗎?

Set EmployeeRS = SecurityDB.Execute("Select count(*) from dbo.personnel where state=1 and lastname not like 'lapt%' and lastname is not NULL and valuelo in (Select ObjectIdLo from area where uiname like 'usmm%' and uiname not like '%gate%') and valuelo <> 1111497912;")