Solved

Sql query  help adding calculated field

Posted on 2011-03-18
2
348 Views
Last Modified: 2012-05-11
I have a sql query that is working well but I need to add another calculated field to and cant seem to get it to work

My Current Query

SELECT     OIBT.ItemCode, OIBT.BatchNum, POR1.ShipDate, POR1.OpenQty, OIBT.InDate, OPOR.CardCode, OPOR.CardName,
                      DATEDIFF(day, isnull(POR1.U_SIF_VENDPROM, POR1.ShipDate),OIBT.InDate) AS dayslate
FROM         OIBT INNER JOIN      
                      OPDN ON OIBT.BaseType = OPDN.ObjType AND OIBT.BaseNum = OPDN.DocNum INNER JOIN
                      PDN1 ON OPDN.DocEntry = PDN1.DocEntry INNER JOIN
                      OPOR INNER JOIN
                      POR1 ON OPOR.DocEntry = POR1.DocEntry ON PDN1.BaseType = OPOR.ObjType AND PDN1.BaseEntry = OPOR.DocEntry AND
                      PDN1.BaseLine = POR1.LineNum
WHERE     (OPOR.U_SIF_PO_Sample = 'Y')

I would like to be able to add another field based on what is populated AS dayslate.

if dayslate (the three following conditions)

< 1 = 'On Time / Early'
< 8 = 'Late 1-7 days'
> 7 = 'Late >7 days'

AS Status
0
Comment
Question by:notasgoodasyou
[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 32

Accepted Solution

by:
Ephraim Wangoya earned 500 total points
ID: 35169218
TRY
SELECT *, CASE  
            WHEN DAYSLATE < 1 THEN 'On Time / Early'
			WHEN DAYSLATE< 8 THEN  'Late 1-7 days'
			ELSE 'Late >7 days'
		  END AS [STATUS]
FROM
	(
	SELECT     OIBT.ItemCode, OIBT.BatchNum, POR1.ShipDate, POR1.OpenQty, OIBT.InDate, OPOR.CardCode, OPOR.CardName, 
						  DATEDIFF(day, isnull(POR1.U_SIF_VENDPROM, POR1.ShipDate),OIBT.InDate) AS dayslate
	FROM         OIBT INNER JOIN      
						  OPDN ON OIBT.BaseType = OPDN.ObjType AND OIBT.BaseNum = OPDN.DocNum INNER JOIN
						  PDN1 ON OPDN.DocEntry = PDN1.DocEntry INNER JOIN
						  OPOR INNER JOIN
						  POR1 ON OPOR.DocEntry = POR1.DocEntry ON PDN1.BaseType = OPOR.ObjType AND PDN1.BaseEntry = OPOR.DocEntry AND 
						  PDN1.BaseLine = POR1.LineNum
	WHERE     (OPOR.U_SIF_PO_Sample = 'Y') 
	) A

Open in new window

0
 

Author Closing Comment

by:notasgoodasyou
ID: 35169238
perfect
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find results from sql within a time span 11 55
SQL - Curser to do an insert based on a select 2 26
SQL profiler 3 18
Can a Trigger trigger a Trigger? 4 22
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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