Solved

SQL Error 207

Posted on 2007-11-14
2
1,550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Conditions in Where clause 9 46
SQL Select - identify record discrepancies 1 31
disk usage reporting tools 27 52
How to trim a value in SQL 2 18
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

756 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