我遇到了訪問sql SELECT語句的問題。問題是,當後端是ACCESS-2007時它起作用;但是當後端是sql-server-2008時,它不會返回任何東西。這裏是語句:訪問sql語句不返回任何內容!
SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11*Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Count]
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between Forms!Meeting_Reasons_Frequency!Text4 And Forms!Meeting_Reasons_Frequency!Text2)) And [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.*'
GROUP BY IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11*Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
HAVING ((Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]))<>0)
ORDER BY IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11*Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
請注意,什麼是不工作是這樣的:Forms!Meeting_Reasons_Frequency!Text4
這Forms!Meeting_Reasons_Frequency!Text2
- 當我更換那些他們工作的恆定值;然而,麻煩在於,由於某些原因,它們沒有正確讀取文本框中的內容。
再次:此查詢正在工作FINE與訪問作爲後端,但是當後端切換到SQL Server它不工作!原因再次是因爲forms!text
的事。有誰知道爲什麼?
更新 多虧了鮑勃的建議,我運行了sql-server上的配置文件,發現有趣的東西。它確實工作正常,但它是這樣返回日期:
@P1 datetime,@P2 datetime','2010-04-30 00:00:00','2010-04-01 00:00:00'
IIF是訪問特定的,而不是SQL/TSQL – 2010-10-21 17:48:22
@omg小馬:此查詢是由接入到SQL/T-SQL轉換。再次,它工作正常,如果我將這些值更改爲常量,而不是從文本框中獲取它們 – 2010-10-21 17:49:11
您可以捕獲在SQL服務器上運行的SQL語句。你應該能夠使用SQL Server Profiler。 Access語句必須轉換爲SQL Server版本。 – bobs 2010-10-21 18:01:59