473,386 Members | 1,694 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,386 software developers and data experts.

Compare dates

I created a temp table
select ol.order_no,ol.date_created,ol.item_id,ol.inv_mast _uid,ol.oe_hdr_uid
INTO #temp
from p21_view_oe_line ol
where datediff(dd,ol.date_created,getdate()) = 7 and
ol.source_loc_id=108843

I have info for last 7 days..

I am trying to generate a report that will be results which will give me the order no for a sale if the sales margin was lower then previously sold.

select distinct oh.taker,oh.order_no,ad.name as 'Customer name',m.item_id,
oh.order_date,
case when oel.extended_price = 0 then 0
else (extended_price - commission_cost) / oel.extended_price end as 'Margin%'
--case when oh.order_date = 0 then 0
--else datediff(dd,oel.date_created,getdate())< (oh.order_date end as 'Previous Order Date'
--(select date_created
--from #temp as [Previous Order Date]
--where datediff(dd,oel.date_created,getdate()) =1
--)
from p21_view_oe_hdr oh
left join p21_view_oe_line oel on oel.order_no=oh.order_no
left join p21_view_address ad on ad.id=oh.customer_id
left join p21_view_inv_mast m on m.inv_mast_uid=oel.inv_mast_uid
left join #temp t on t.date_created=oel.date_created
and m.inv_mast_uid=t.inv_mast_uid
and t.item_id=oel.item_id
and t.date_created < oel.date_created and t.oe_hdr_uid=oh.oe_hdr_uid
where oh.location_id=108843
--datediff(dd,oel.date_created,getdate())< oh.order_date as
--and oel.date_created < getdate ()
order by 1

the abover query gives me the new orders but i need to add code where i can find if there was a previous order ?
Dec 3 '08 #1
2 1801
ck9663
2,878 Expert 2GB
Could you post some sample data and how you want your result?

-- CK
Dec 3 '08 #2
Taker Order_no Customer_Name Item_Id Order_date Margin% Previous Order date
ADEL 1829854 R & T REPAIR SERVICE SUP B28 38:30.0 92% 44:42.8
ADEL 1829854 R & T REPAIR SERVICE VICTO 1407-0013 38:30.0 84% 44:42.8
ADEL 1838392 CO WELDING SUPPLY INC PACKAGING/HANDLING/DELIVERY, OUT 10:28.0 101% 44:42.8
ADEL 1847612 SP INDUSTRIES INC ARMSTR 069-78-110 10:58.0 112% 44:42.8
ADEL 1847612 SP INDUSTRIES INC ARMSTR 069-78-112 10:58.0 129% 44:42.8
ADEL 1847639 SP INDUSTRIES INC ARMSTR 069-78-110 30:51.0 112% 44:42.8

please check the attachment for the excel doc
Dec 3 '08 #3

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

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
3
by: jrc4728 | last post by:
I have a MySQL table with the date stored in three fields as string values like this. (sorry, its imported data) str_yy str_dd str_mm ------------------------ 05 01 04 05 ...
4
by: alexis | last post by:
Hi, In a form I have the curent date <input name="datetoday" type="hidden" value="<? echo date("d/m/Y"); ?>"> and <input type=text name="datebox" size=15> The date format is d/m/Y...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
9
by: Rich | last post by:
Thanks for the Help in my previous post. I've been working on this and it's almost what I want. I want to obtain the user's current age by comparing their date of birth (user inputs) to the...
9
by: Rimuen | last post by:
Have two text form with dates i need to compare before submitting, the second should always be a date later the first one. Anyone have a script for this ?? Thanks.......
1
by: godsella | last post by:
First i have two stored procedures, i have passed the values of each one into two different arraylists of dates. how can i compare the two arraylists of dates? Thanks in advance
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: cd123 | last post by:
Hi, I used Date object of Javascrips to compare two dates like one is the from date and the other is to date. var obj1 = new Date(from date); var obj2 = new Date(to date); then i used...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.