Solved

SQL Error 207

Posted on 2007-11-14
2
1,541 Views
Last Modified: 2012-08-13
On this piece of sql code I'm getting an error. Here is the code:

(OID.[Pieces]-OID.[delivered]) AS NotShipped,  CONVERT(INT,NotShipped/CIL.[Unit]) AS Cases, NotShipped % CIL.[Unit] AS Piece,

and here is the Error:
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'NotShipped'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'NotShipped'.

The error is with this piece of code:
CONVERT(INT,NotShipped/CIL.[Unit]) AS Cases, NotShipped % CIL.[Unit] AS Piece,

What am I doing wrong? am I not able to refer to a previously created column?

0
Comment
Question by:Tammak1
2 Comments
 
LVL 31

Expert Comment

by:James Murrell
ID: 20284682
what columns are in the table
0
 
LVL 25

Accepted Solution

by:
imitchie earned 50 total points
ID: 20284782
you can't use a named column in the select statement. put it in a a subquery. i.e.

select *, CONVERT(INT,NotShipped/[Unit]) AS Cases, NotShipped % [Unit] AS Piece
from
(
select
field1, field2, field3, (OID.[Pieces]-OID.[delivered]) AS NotShipped, field5
from table
) innertable

either that or

(OID.[Pieces]-OID.[delivered]) AS NotShipped,  CONVERT(INT,(OID.[Pieces]-OID.[delivered])/CIL.[Unit]) AS Cases, (OID.[Pieces]-OID.[delivered]) % CIL.[Unit] AS Piece,
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now