473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Converting SQL Server 2000 query to MS Access 2000 query

Hello!
I am trying to convert a query written for SQL Server 2000 database
tables, to a MS Access query.
Here is what I have in SQL Server:

SELECT t2.*,
CASE WHEN t2.QType = '3' THEN t1.Note ELSE CASE WHEN t2.QType = '2'
THEN
CASE WHEN CONVERT(varchar(100), t1.ANumber) = '1' THEN 'Yes' ELSE 'No'
END ELSE CASE WHEN CONVERT(varchar(5), t2.Qnumber)+'.' +
CONVERT(varchar(5), t1.ANumber)
= t2.SubQ THEN 'Selected' ELSE 'Not Selected'
END END END
AS Client_Response
FROM (SELECT * FROM ClientAnswer
WHERE (OrganizationID = '491') AND (InstrumentId = 'CM005')) AS
t1
RIGHT JOIN
(SELECT Questions.InstrumentId, Questions.Qnumber,
Questions.Question,
Questions.QType,
CASE WHEN TEMPT.A IS NULL THEN QNumber ELSE TEMPT.A END AS
SubQ,
CASE WHEN TEMPT.Answer IS NULL THEN Questions.Question ELSE
TEMPT.Answer END AS Answer
FROM Questions LEFT OUTER JOIN
(SELECT QNumber AS Q, Answer, CONVERT(varchar(5), QNumber)
+ '.' +
CONVERT(varchar(5), ANumber) AS A
FROM Answers
WHERE InstrumentId = 'CM005')) TEMPT
ON Questions.Qnumber = TEMPT.Q
WHERE (Questions.InstrumentId = 'CM005')) AS t2
ON t1.QNumber = CASE WHEN t2.QType <> '1' THEN t2.Subq ELSE t2.QNumber
END
ORDER BY subq
It runs perfectly on the SQL Server, however it keeps giving me
"Invalid use of null" or "The statement is not written properly or is
too complex.." errors.
Here is the Access statement I am trying to run:

SELECT IIF(cstr(t2.QType) = '3', t1.Note, IIF(cstr(t2.QType) =
'2', IIF( cstr(t1.ANumber) = '1','Yes','No'), IIF( cstr(t2.Qnumber) +
'.' + cstr(t1.ANumber) = t2.SubQ, 'Selected', 'Not Selected')))
AS Client_Response
FROM (SELECT * FROM ClientAnswer
WHERE (cstr(OrganizationID) = '491') AND (InstrumentId = 'CM005')) AS
t1
RIGHT JOIN
(SELECT Questions.InstrumentId, Questions.Qnumber, Questions.Question,
Questions.QType, iif(TEMPT.A = NULL, QNumber, TEMPT.A) AS SubQ,
iif(TEMPT.Answer = NULL, Questions.Question, TEMPT.Answer) as Answer
FROM Questions
LEFT OUTER JOIN
(SELECT QNumber AS Q, Answer, cstr(QNumber) + '.' + cstr(ANumber) AS A
FROM Answers WHERE (InstrumentId = 'CM005')) TEMPT ON
Questions.Qnumber = TEMPT.Q
WHERE (Questions.InstrumentId = 'CM005'))
AS t2 ON t1.QNumber = iif(t2.QType <> '1', t2.Subq, t2.QNumber)
ORDER BY subq

I HATE ACCESS!!!
Please help...
Nov 12 '05 #1
1 5291
"Stefan V." <st************@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
Hello!
I am trying to convert a query written for SQL Server 2000 database
tables, to a MS Access query.
Here is what I have in SQL Server:

SELECT t2.*,
CASE WHEN t2.QType = '3' THEN t1.Note ELSE CASE WHEN t2.QType = '2'
THEN
CASE WHEN CONVERT(varchar(100), t1.ANumber) = '1' THEN 'Yes' ELSE 'No'
END ELSE CASE WHEN CONVERT(varchar(5), t2.Qnumber)+'.' +
CONVERT(varchar(5), t1.ANumber)
= t2.SubQ THEN 'Selected' ELSE 'Not Selected'
END END END
AS Client_Response
FROM (SELECT * FROM ClientAnswer
WHERE (OrganizationID = '491') AND (InstrumentId = 'CM005')) AS
t1
RIGHT JOIN
(SELECT Questions.InstrumentId, Questions.Qnumber,
Questions.Question,
Questions.QType,
CASE WHEN TEMPT.A IS NULL THEN QNumber ELSE TEMPT.A END AS
SubQ,
CASE WHEN TEMPT.Answer IS NULL THEN Questions.Question ELSE
TEMPT.Answer END AS Answer
FROM Questions LEFT OUTER JOIN
(SELECT QNumber AS Q, Answer, CONVERT(varchar(5), QNumber)
+ '.' +
CONVERT(varchar(5), ANumber) AS A
FROM Answers
WHERE InstrumentId = 'CM005')) TEMPT
ON Questions.Qnumber = TEMPT.Q
WHERE (Questions.InstrumentId = 'CM005')) AS t2
ON t1.QNumber = CASE WHEN t2.QType <> '1' THEN t2.Subq ELSE t2.QNumber
END
ORDER BY subq

1. Format the original statement with line breaks and indentations, (easy to
do in Query Analyzer). It makes the code much easier to read - for us as
well as you.
2. Use IIf or the Switch statement, (depending on number of conditaions)
instead of CASE .. WHEN .. ELSE
3. Use CLng to convert text to numeric datatype and CStr to go the other way
4. CASE .. WHEN IS NULL THEN can be replaced by COALESCE in sql server and
Nz() in Access (Jet)
5. Use RIGHT OUTER join instead of RIGHT JOIN (I'm not 100% sure but IU
don't think you can use RIGHT JOIN in Access)
And some general notes
6. It looks like the first CASE statement can be simplified - case gives you
a choice between 1, 2, 3 .. n options - you don't have to embed multiple
case statetements as you would do with IIf.
7. Why do you alias some tables and not others?
8. SELECT t2.* is not good sql programming - it's better to explicitly
declare all your columns.
..




Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
9
by: wiredog | last post by:
I am struggling rewriting my query from MS Access' IIF, Then to SQL Servers TSQL language. I am hoping some one can give me some guidance. I believe I have the first portion of the query correct...
4
by: dschl | last post by:
Hi, I'm converting an Access 2000 database to Sql Server and must be missing something obvious. Using the Import utility in Sql Server, the Access queries seem to get executed and the...
7
by: Dana Shields | last post by:
I am attempting to upsize from access to SQL Server. I'm trying to convert my queries to SQL Server views; however, I'm having a lot of difficulty with the syntax differences. For instance, a...
1
by: Stefan V. | last post by:
Hello! I am trying to convert a query written for SQL Server 2000 database tables, to a MS Access query. Here is what I have in SQL Server: SELECT t2.*, CASE WHEN t2.QType = '3' THEN...
0
by: Timppa | last post by:
Hi, I'm converting ACCESS 2000 database to SQL Server. I have .adp project. In the .mdb I have form where I'll insert rows into two different tables using docmd.GoToRecod ,,acNewRec. In .adp...
2
by: Mark Flippin | last post by:
I'm converting the backend of an Access 2000 database to SQL Server 2000. The existing database has user and group security through a specific workgroup file. Under the "user and group...
2
by: ILCSP | last post by:
Hello, I have the following query in Access 2000 that I need to convert to SQL 2000: UPDATE tblShoes, tblBoxes SET tblShoes.Laces1 = Null WHERE (((tblShoes.ShoesID)=Int(.)) AND...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.