473,395 Members | 1,891 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,395 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 5292
"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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.