Hi,
I made a query that gives me all the information that i need for my final report but it i have a difficult time on how to get my required final output. I wanted to pull all those esn1 that has the following op_status as CMA Receive including Open, create order, shipping and finished good specially the CMA Recieve which pertains that this esn is receive it. any help is very much appreciated. thank you.
below is my DDL.. the sample data is the result of my main query the sample desired result.
[code]create table #sample1
(esn1 nvarchar(35), esn2 nvarchar(35), esn3 nvarchar(35), idnum nvarchar(35), trandate datetime, supplier varchar(5), model nvarchar(35), opDesc nvarchar(35), op_status nvarchar(35))
insert into #sample1
select 'B1000000000022422990','058536058570426','058536058570426','PRC006731939','2016-01-06 04:21:56.080','TCS','TALV6000425iPH5C16','CMA Receive','CMA Receive'
union all
select 'B1000000000022422990','058536058570426','058536058570426','PRC006731939','2016-01-06 04:21:57.717','TCS','TALV6000425iPH5C16','CMA shipped','CMA Shipped'
union all
select 'B1000000000022422990','058536058570426','058536058570426','PRC006731939','2016-01-22 23:44:57.000','PROD','N600-0425-IPH5C16-U','Created Order','Creatde Order'
union all
select 'B1000000000022422990','058536058570426','058536058570426','PRC006731939','2016-01-24 00:24:57.000','PROD','N600-0425-IPH5C16-U','Order Complete','Finished good'
union all
select 'B1000000000022422990','058536058570426','058536058570426','PRC006731939','2016-01-24 05:39:08.410','TLK','N600-0412-IPH5C16-U','Shipping','Shipping'
union all
select '013329006770539','513329006770539','NULL','NULL','2016-01-05 04:38:59.620','TLK','N231-0440-IPH5C8-U','Receive','Receive'
union all
select '013329006770539','513329006770539','NULL','NULL','2016-01-05 04:39:14.947','TLK','N231-0440-IPH5C8-U','Pass','Pass'
union all
select 'B1000000000020074152','654452062437950','654452062437950','PRC006708329','2016-01-19 00:07:40.000','PROD','N400-0560-iPH6P128-U','Created Order','Created Order'
union all
select 'B1000000000020074152','654452062437950','654452062437950','PRC006708329','2016-01-22 17:15:16.000','PROD','N400-0560-iPH6P128-U','Order Complete','Finished Good'
union all
select 'B1000000000020074152','654452062437950','654452062437950','PRC006708329','2016-01-23 01:22:52.427','TLK ','SHELL4000430iPH6P64SIL','Shipping','Shipping'
union all
select 'B1000000000022541529','B1000000000022541529','NULL','NULL','2016-01-20 12:19:44.027','EXS','TALV8000460iPH664','CMA Receive','CMA Receive'
union all
select 'B1000000000022541529','B1000000000022541529','NULL','NULL','2016-01-20 12:19:45.820','EXS','TALV8000460iPH664','CMA shipped','CMA shipped'
union all
select 'B1000000000022541529','B1000000000022541529','358373064606949','PRC006730640','2016-01-22 20:13:38.000','PROD','N400-0460-IPH664-U','Create Order','Open'
--Desired Result
result 1
model------------esn1------------------esn2-------------------esn3--------------------------------CMA receiptdate-----Created Order date -----Order Complete date---------shipping date------------op_status
TALV6000425iPH5C16----B1000000000022422990--058536058570426-------058536058570426--2016-01-06 04:21:57.717---2016-01-22 23:44:57.00-- 2016-01-24 00:24:57.00-- 2016-01-24 05:39:08.410----Finished good
TALV8000460iPH664-----B1000000000022541529--B1000000000022541529-------------------2016-01-22 20:13:38.000--- ----------------------------------------------------------------------------Open
result 2
esn1------------------esn2------------------esn3--------------idnum--------trandate----------------supplier--- model----------opDesc---------op_status
B1000000000022422990--058536058570426-------058536058570426--PRC006731934-- 2016-01-06 04:21:56.080--TCS----TALV6000425iPH5C16---CMA Receive-- CMA Receive
B1000000000022422990--058536058570426-------058536058570426--PRC006731934-- 2016-01-06 04:21:57.717--TCS----TALV6000425iPH5C16---CMA Shipping---CMA Shipping
B1000000000022422990--058536058570426-------058536058570426--PRC006731934-- 2016-01-22 23:44:57.000--PROD---N600-0425-IPH5C16----Created Order--Creatde Order
B1000000000022422990--058536058570426-------058536058570426--PRC006731934-- 2016-01-24 00:24:57.000--PROD---N600-0425-IPH5C16----Order Complete--Finished good
B1000000000022422990--058536058570426-------058536058570426--PRC006731934-- 2016-01-24 05:39:08.410--TLK----N600-0412-IPH5C16----Shipping --Shipping
B1000000000022541529--B1000000000022541529--NULL-------------NULL---------- 2016-01-20 12:19:44.027--EXS----TALV8000460iPH664----CMA Receive-- CMA Receive
B1000000000022541529--B1000000000022541529--NULL-------------NULL---------- 2016-01-20 12:19:45.820--EXS----TALV8000460iPH664----CMA Shipping-- CMA Shipping
B1000000000022541529--B1000000000022541529--358373064606949--PRC006730647-- 2016-01-22 20:13:38.000--PROD---N400-0460-IPH664-----Create Order-- Open[/code]