Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Scripting help needed

(0) ShareShare
ReportReport
Posted on by 1,203

I have a query with 4 columns like the following

Select PAPROJNUMBER, PACOSTCATID,EMPLOYID, PADT,  PABase_Qty from PTE10001

PAPROJNUMBER    PACOSTCATID    EMPLOYID        PADT                     PABase_Qty
HOTELEDGER      CONSULTING      ACKE0001        2017-04-09 00:00:00.000 1.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-09 00:00:00.000 2.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-09 00:00:00.000 2.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-09 00:00:00.000 4.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-09 00:00:00.000 6.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-10 00:00:00.000 3.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-10 00:00:00.000 4.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-10 00:00:00.000 2.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-11 00:00:00.000 0.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-11 00:00:00.000 0.00000
HOTELEDGER      CONSULTING      ACKE0001        2017-04-11 00:00:00.000 3.00000

I am looking for something like this as an output

PAPROJNUMBER    PACOSTCATID    EMPLOYID       4/9/17   4/10/17  4/11/17 
HOTELEDGER      CONSULTING      ACKE0001        1.00    3.00     0.00 
HOTELEDGER      CONSULTING      ACKE0001        2.00    4.00     0.00 
HOTELEDGER      CONSULTING      ACKE0001        2.00    2.00     3.00 
HOTELEDGER      CONSULTING      ACKE0001        4.00    0.00     0.00 
HOTELEDGER      CONSULTING      ACKE0001        6.00    0.00     0.00 

Is there anyone who can assist me with this?

*This post is locked for comments

  • Kumar_Sat Profile Picture
    Kumar_Sat 1,203 on at
    RE: Scripting help needed

    Thanks Mick and Leslie.

  • Suggested answer
    Mick Egan Profile Picture
    Mick Egan 3,561 on at
    RE: Scripting help needed

    Have a look at this sample code I put together, will get you started.

    I needed to add the convert for the dates to match on my setup.

    The original Hours Column and PADT date are shown for comparison and can be removed once testing is confirmed.

    As Leslie mentioned you could even spend time with the pivot statements.

    declare @Day1 as datetime

    declare @Day2 as datetime

    declare @Day3 as datetime

    declare @Day4 as datetime

    select @Day4 = getdate(), @Day3 = @Day4 - 1, @Day2 = @Day4 - 2, @Day1 = @Day4 - 3

    create table [tag:Temp]

    (

    PAPROJNUMBER char (65),

    Employid char (65),

    TrxHours numeric (14,2),

    TrxDate Datetime,

    Day1 numeric (14,2),

    Day2 numeric (14,2),

    Day3 numeric (14,2),

    Day4 numeric (14,2)

    )

    insert into [tag:Temp]

    select PAPROJNUMBER, EMPLOYID, PTE_Quantity, PADT,  

    (case when PADT = convert(char (10), @Day1, 121) then PTE_Quantity else 0 end),

    (case when PADT = convert(char (10), @Day2, 121) then PTE_Quantity else 0 end),

    (case when PADT = convert(char (10), @Day3, 121) then PTE_Quantity else 0 end),

    (case when PADT = convert(char (10), @Day4, 121) then PTE_Quantity else 0 end) from PTE10001 where PADT > '2017-08-17'

    Select *  from [tag:Temp]

    drop table [tag:Temp]

    -------------------------------

    Regards,

    Mick

  • Suggested answer
    L Vail Profile Picture
    L Vail 65,271 on at
    RE: Scripting help needed

    I think you need to use the PIVOT statement in SQL

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,329 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans