February 24, 2014 at 2:52 am
Sorry, this is probably really obvious to most of you, but I cant work it out.
Here is my PIVOT SQL:
SELECT
[PLACE-REF],[JOB-NO],[08. Actual Finish],[07. Actual Start]
FROM
#MI_JOB_STAGES2
PIVOT (
MAX([STAGE-DATE]) for [STAGE-DESC-ALTERNATE] in ([08. Actual Finish],[07. Actual Start])
)p
This is the result:
PLACE-REF JOB-NO08. Actual Finish07. Actual Start
500024 A03953662013-04-03NULL
500024 A0395366NULL 2013-04-01
500103 A03953682013-04-03NULL
500103 A0395368NULL 2013-04-01
500529 A03203352012-09-14NULL
As you can see the result are not unique:
I want this:
PLACE-REF JOB-NO08. Actual Finish07. Actual Start
500024 A03953662013-04-032013-04-01
500103 A03953682013-04-032013-04-01
500529 A03203352012-09-14NULL
I know this is probably obvious but any help would be appreciated.
Thanks
February 24, 2014 at 2:56 am
Could you please post table definitions and some sample data (as insert statements)? See http://www.sqlservercentral.com/articles/Best+Practices/61537/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 24, 2014 at 3:32 am
I was creating the scripts for the table definitions and data,
but after simplifying it for this forum, I was getting the result I was expecting.
I think it was because I had additional columns that I wasn't using in the temp table.
I knew It was going to be something obvious.
Thanks again.
February 24, 2014 at 4:17 am
huw.pickrell (2/24/2014)
I was creating the scripts for the table definitions and data,but after simplifying it for this forum, I was getting the result I was expecting.
That happens so often. 🙂
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply