Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Subprime Accountant
Starting Member
3 Posts |
Posted - 2009-02-02 : 10:50:44
|
| Greetings, Using Microsoft Query 2002. The following query pulls A/P information for specific GL's from both historical and current tables. That part works correctly. I Rtrim the P.O. Numbers to get rid of junk and return only values. The Trim works correctRIGHT(PM20000.PORDNMBR,4)AS 'P.O.' but everytime I try to name the column as 'P.O.' MSQuery just deletes the AS clause from my script and returns and unnamed column.The following is the script -SELECTPM20000.DOCTYPE, PM20000.VENDORID, PM20000.DOCDATE, PM20000.DOCAMNT, GL00105.ACTNUMST, GL00100.ACTDESCR,RIGHT(PM20000.PORDNMBR,4)AS 'P.O.' FROM CRW.dbo.PM20000 PM20000LEFT OUTER JOIN CRW.dbo.PM10100 PM10100ON PM20000.VCHRNMBR = PM10100.VCHRNMBRLEFT OUTER JOIN CRW.dbo.GL00100 ON PM10100.DSTINDX = CRW.dbo.GL00100.ACTINDXLEFT OUTER JOIN CRW.dbo.GL00105 ON PM10100.DSTINDX = CRW.dbo.GL00105.ACTINDXWHERE(GL00105.ACTNUMST='10-12270-00-00000') OR(GL00105.ACTNUMST='10-12271-00-00000') OR(GL00105.ACTNUMST='10-12271-00-00001') OR(GL00105.ACTNUMST='10-12273-00-00000')UNIONSELECTPM30200.DOCTYPE, PM30200.VENDORID, PM30200.DOCDATE, PM30200.DOCAMNT, GL00105.ACTNUMST, GL00100.ACTDESCR,RIGHT(PM30200.PORDNMBR,4) AS 'P.O.' FROM CRW.dbo.PM30200 PM30200LEFT OUTER JOIN CRW.dbo.PM30600 PM30600ON PM30200.VCHRNMBR = PM30600.VCHRNMBRLEFT OUTER JOIN CRW.dbo.GL00100 ON PM30600.DSTINDX = CRW.dbo.GL00100.ACTINDXLEFT OUTER JOIN CRW.dbo.GL00105 ON PM30600.DSTINDX = CRW.dbo.GL00105.ACTINDXWHERE (GL00105.ACTNUMST='10-12270-00-00000') OR(GL00105.ACTNUMST='10-12271-00-00000') OR(GL00105.ACTNUMST='10-12271-00-00001') OR(GL00105.ACTNUMST='10-12273-00-00000')Here is what the query returnsACTNUMST ACTDESCR 10-12273-00-00000 Inventory-Parts-CRW 562710-12273-00-00000 Inventory-Parts-CRW 563010-12273-00-00000 Inventory-Parts-CRW 562910-12273-00-00000 Inventory-Parts-CRW Any advice would be greatly appreciated.Your Friend, And Mine... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-02 : 10:54:13
|
| try RIGHT(PM20000.PORDNMBR,4) AS [P.O.] instead.b/w whats Microsoft Query 2002? |
 |
|
|
Subprime Accountant
Starting Member
3 Posts |
Posted - 2009-02-02 : 12:26:02
|
| I thank you for your suggestion, however, it has proven unsuccessful.To answer your question: I am querying using the SQL tool imbebbed in Excel: Data, Import Externa Data, Edit Query... and you end up in with a graphical query tool.Your Friend, And Mine... |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-02 : 12:36:47
|
try this,[P.O.]=RIGHT(PM20000.PORDNMBR,4) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
Subprime Accountant
Starting Member
3 Posts |
Posted - 2009-02-02 : 13:45:24
|
| My system was up to date on Service Packs.I ran the hot fix, to no avail. Modifying the query to SELECT PM20000.DOCTYPE, PM20000.VENDORID, PM20000.DOCDATE, PM20000.DOCAMNT, RIGHT(PM20000.PORDNMBR,4) AS PO FROM CRW.dbo.PM20000 PM20000This correctly renames my column. My guess is somehow the joins limit the functionality, as I've tried the query from the union up and it would not rename the column while including any of the GL tables. Your Friend, And Mine... |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2009-02-02 : 15:31:25
|
| Create a view in SQL Server, defined however you want and returning any columns/expressions that you want with the labels you need, and then simply query the View from MS Query.This will be much easier to maintain anyway going forward, and probably more flexible and more efficient as well.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
|
|
|
|
|