Link to home
Start Free TrialLog in
Avatar of sqlcurious
sqlcuriousFlag for United States of America

asked on

Need help with sql coding

Project     |    PONum            |    PODesc
200078        3152000745      PTNumber
200078        3153000135      CANumber
200078      3153000235          CANumber
200090      3153000234          PTNumber

For the above give sample table, I should get a result as below: For every project number if there are multiple PONum, I need to consider only the first two and display them as PONum1(3152000745), PONum2 ,PODesc1 and PODesc2 resp.
ex the above table should show as below:

project   |  PONum1      |   PODesc1 |  PONum2       |   PODesc2
200078  | 3152000745 | PTNumber | 3153000135 |  CANumber
200090  | 3153000234 | PTNumber |                       |  

Thanks!
Please note that the third PONumber for the first project number is ignored. only the first two are considered.


ASKER CERTIFIED SOLUTION
Avatar of tim_cs
tim_cs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sqlcurious

ASKER

Thanks a lot it worked!!! Can you please tell me the exact meaning of the code though, would like to understand it better.
Avatar of Anthony Perkins
Start by reading up on CTEs in SQL Server BOL.  Let me know if you need a link.
thnks