473,418 Members | 2,338 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,418 software developers and data experts.

Error: incorrect syntax near the keyword AS

Expand|Select|Wrap|Line Numbers
  1. SELECT mcr2008.st, (SUM(mcr2008.bedsize)-SUM(mcr2007.bedsize))/SUM(mcr2007.bedsize) 
  2. FROM
  3.     (
  4.         (
  5.         SELECT mcrid, st , SUM(bedsize) as bedsize   
  6.         FROM MCRCR_96_to_08 
  7.         WHERE yr=2008
  8.         GROUP BY  mcrid, st  
  9.         ) as MCR2008
  10.  
  11.         INNER JOIN 
  12.  
  13.         (
  14.         SELECT  mcrid, st, SUM(bedsize)as bedsize
  15.         FROM MCRCR_96_to_08 
  16.         WHERE yr=2007
  17.         GROUP BY  mcrid, st 
  18.         ) as MCR2007        
  19.  
  20.         ON MCR2007.mcrid=MCR2008.mcrid 
  21.     ) as A
  22. GROUP BY st;
Oct 17 '10 #1
1 2051
gpl
152 100+
You dont need the AS keyord when declaring a derived table, also the outer A table means the inner aliases will not be visible, try this
Expand|Select|Wrap|Line Numbers
  1. SELECT mcr2008_st, (SUM(mcr2008_bedsize)-SUM(mcr2007_bedsize))/SUM(mcr2007_bedsize)
  2. FROM
  3.     (
  4.         (
  5.         SELECT mcrid as MCR2008_mcrid, st as MCR2008_st , SUM(bedsize) as MCR2008_bedsize
  6.         FROM MCRCR_96_to_08 
  7.         WHERE yr=2008
  8.         GROUP BY  mcrid, st  
  9.         )  MCR2008
  10.  
  11.         INNER JOIN 
  12.  
  13.         (
  14.         SELECT  mcrid as MCR2007_mcrid, st as MCR2007_st, SUM(bedsize)as MCR2007_bedsize
  15.         FROM MCRCR_96_to_08 
  16.         WHERE yr=2007
  17.         GROUP BY  mcrid, st 
  18.         ) MCR2007
  19.  
  20.         ON MCR2007_mcrid=MCR2008_mcrid
  21.     ) A
  22.   GROUP BY MCR2008_st
  23.  
Oct 17 '10 #2

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

Similar topics

5
by: J. Muenchbourg | last post by:
IN the code below, I am getting an Incorrect Syntax near "," error (the sql execute line, and it is pointing to position 1 ) (the display formatting here may look different than my script): ...
1
by: Amit D.Shinde | last post by:
Hi Experts, i am writting a stored procedure in sql server 7. Its a simple stored procedure It is my first stored procedure. I want insert a record in table if the primary key field user id...
1
by: Jeff Magouirk | last post by:
Dear Group, I am trying to create a view and keep getting the Incorrect syntax near the keyword 'Declare'" error. Here is the code I am writing. Create view fixed_airs (sid, fad_a2, fad_a3)...
11
by: Mark Findlay | last post by:
Hello Experts! I am attempting to use the OleDbCommand.ExecuteScaler() function within my ASP.NET C# web page to perform a simple validation, but receive the following error: "Incorrect...
2
by: Jon | last post by:
hi, i was trying to create a DB in a SQL Server. but when i try to connect it with : Dim conn As SqlConnection = New SqlConnection("Initial Catalog=master; " & _ "Data Source=SERVER-MACHINE;" &...
1
by: Dax | last post by:
When i insert some values float in a form made with ASP appear an error message like this: Microsoft OLE DB Provider for SQL Server (0x80040E14) Line 1: Incorrect syntax near ','. sql="select...
1
by: mabubakarpk | last post by:
HI. I am using SQL Server 2000. I generate a script of some table from EmpDB database when I run script in query analyzer it return error "Incorrect syntax near 'COLLATE'." Scripts is ...
3
by: wallic | last post by:
Hello, This is my first post and I am a beginner with SQL code. The code below is supposed to update a new table (loctable) with a calculated value based on the original table (hra_data). ...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
3
by: teddymeu | last post by:
Hi Guys, new to development using visual studio and vb.net 2.0. and SQL express. Have a small problem. I have an update command which im using to change the values of a blob image table to NULL...
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: 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:
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.