473,387 Members | 1,493 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,387 software developers and data experts.

SQL query runs in Microsoft SQL Server Management Studio but not in Access 2007

The following section, from an sql query, runs perfectly in Microsoft SQL Server Management Studio:
Expand|Select|Wrap|Line Numbers
  1. the_section=(case when line_no= 101 then 1 when line_no  between 102 
  2. and 105 then 2 when line_no  between 106 
  3. and 112 then 2 when line_no  between 201 
  4. and 219 then 3 when line_no  between 703 
  5. and 704 then 2 when line_no  between 801 
  6. and 822 then 2 when line_no  between 901 
  7. and 910 then 2 when line_no  between 1001 
  8. and 1016 then 2 when line_no  between 1101 
  9. and 1128 then 2 when line_no  between 1201 
  10. and 1210 then 2 when line_no  between 1301 
  11. and 1310 then 2 else 3 end),
The table column "line_no" exists in one of the linked tables that is part of the query but the column "the_section" is being created to hold data only for the query.

When I try to run this in Access 2007 I get the following error message:

The Microsoft Office Access database engine could not find 'the_section=(case when line_no=101 then 1 when line_no between 102
and 105 then 2 when line_no between 106
and 112 then 2 when line_no between 201
and 219 then 3 when line_no between 703
and 704 then 2 when line_no between 801
and 822 then'. Make sure the object exists and that you spell its name and the path name correctly.

Can someone please help?
Apr 22 '10 #1
7 2113
NeoPa
32,556 Expert Mod 16PB
SQL Server uses a flavour of SQL called T-SQL or Transact-SQL. The flavour used in Access is Jet SQL. They are not fully compatible. You cannot simply copy/paste from one to the other.
Apr 22 '10 #2
Thank You -- That solves the problem -- I see in Jet SQL that I have to use an "IIF" as opposed to "case when" in T-SQL
Apr 22 '10 #3
NeoPa
32,556 Expert Mod 16PB
You also have other functions available for choosing results dependent on other data, such as Choose() & Switch(). The most common one seems to be IIf() though, certainly.

Welcome to Bytes!
Apr 22 '10 #4
With T-SQL if you write something like: amount = 1 and amount is not a defined column in the table you are using to draw data from, it will make a column named "amount" and fill it with the value 1

In Jet-SQL with Microsoft Acces if you do this you get a pop up box that ask you to enter the parameter value for "amount".

Why and how can this be changed to get the same results that I get with T-SQL
Apr 22 '10 #5
hilaDG
6
from my experience, SQL handles all those CASE.. WHEN way more gracefully then MS-access.
Create an ODBC server, and go to the tables and use link tables in order to link to that SQL server. This way you don't have to re-create the entire table definitions, etc, with MS-Access
Apr 23 '10 #6
hilaDG
6
@Lawless
If you don't have a column defined access would never define one for you. It could be so many things other then a column: a form, a text box, a query, that access simply cannot assume a column. So if you want one you'll have to define it by yourself.
Apr 23 '10 #7
NeoPa
32,556 Expert Mod 16PB
It seems you're confusing columns with variables (If my T-SQL knowledge is at all reliable). I must admit I have never used a variable name that didn't start with an @. I didn't realise it was even supported. I'm trying to think if maybe my understanding is just too limited and perhaps it is a column after all, but I cannot imagine how that would make any sense at all. I certainly know of know way to duplicate either in Jet SQL.

I would add one other comment that you can take on board if you like, that I never recommend the use of any type of variable, even a temporary one, that is not already defined or declared. On-the-fly variables are the cause of so many problems, especially in the area of maintenance.
Apr 23 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Novice | last post by:
Hi all, I am a C++ and Java developer with over 3 years of industry experience. I've written low level C++ code, in addition to web clients that use web services. I've just recently installed the...
4
by: Edward | last post by:
Hi All, Thanks upfront for any help given me. I just installed Visual Studio 2005 Professional & Sql Server on an XP SP2 PC and I do not see the old Sql Server Enterprise Manager and Sql...
1
by: Crazy Cat | last post by:
I'm calling several SQL Server 2005 stored procedures from Visual Basic 2005. I've got one stored procedure that locks up at the same point everytime, but if I copy the stored procedure from the...
3
by: alvinstraight38 | last post by:
Hi everyone, I am trying to access a client's SQL query anaylzer to run a SQL script, and I can not find it anywhere. I have not used SQL in a few years, but I would always see a menu in the...
4
by: Goofy | last post by:
The add database ( MDF ) in Visual Studio 2005 seems to be in SQL Server 2005 format as far as I can tell. Does anyone know how I can import tables ( without having to start writing queries ) from...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
3
by: =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= | last post by:
Has anyone successfully used an Access query from .NET? I am trying to do this and am getting a weird error. .NET calls queries 'stored procedures'. The error I am getting says "Schema could not be...
4
by: Uriah Piddle | last post by:
Hi Gang, In sql Server 2005, I am running a query with an nvarchar param in the WHERE clause like this: .. . . @Bar nvarchar .. . . Select * From Foo WHERE Foo.Bar = @Bar The problem:...
3
by: pmacdiddie | last post by:
I have this query that when run on Access 2007 works, when run in 2002 it fails with the following error: Incorrect Syntax near '.'. INSERT INTO tblQualitySurvey ( Company, Job_Num,...
9
by: Mourad | last post by:
Hi All, Is it possible to create a Make Table query in access (2.0 and 2003) that creates the table into a SQL Server database? Following the steps: 1- Create New Query 2- Set Query Type as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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?
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
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
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...

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.