Solved

Sql query  help adding calculated field

Posted on 2011-03-18
2
358 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 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