Removing leading zeros from PO_Number, (using OPENQUERY)

I've tried the following 3 things to remove the leading zeros from PO_Number, (using OPENQUERY) in the workbench without success, any other suggestions please?
- Using CAST and LTRIM:
SELECT *
FROM OPENQUERY(ACME_CO_PRD,
'SELECT
LTRIM(CAST(CAST(fd.PO_NO AS INT) AS VARCHAR)) AS PO_No,
2. Using PATINDEX and SUBSTRING:
SELECT *
FROM OPENQUERY(ACME_CO_PRD,
'SELECT
SUBSTRING(fd.PO_NO, PATINDEX(''%%'', fd.PO_NO + ''0''), LEN(fd.PO_NO)) AS PO_No,
3. Using STUFF and PATINDEX:
SELECT *
FROM OPENQUERY(ACME_CO_PRD,
'SELECT
STUFF(fd.PO_NO, 1, PATINDEX(''%%'', fd.PO_NO + ''0'') - 1, '''') AS PO_No,
Best Answer
-
0
Answers
-
have you looked into utilizing a transform on the workbench job after your query is run?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
I have tried your suggestion in the following 2 ways, I am getting a workbench error: Value cannot be null (parameter name: replacement):
- Add a Search/Replace Transform in one step:
Click on the "Add Transform" button and select "Search/Replace Transform" from the menu.
In the Search/Replace Transform Editor, select the PO_No column from the "Search Column" menu.
In the "Search Value" field, enter the regular expression to find leading zeros. Use ^0+ to match one or more leading zeros. In the "Replace With" field, leave it blank to remove the placeholder character.
Search Value: #
Replace With: (leave this field blank)
2. Add a Search/Replace Transform in two steps:
Navigate to the "Transforms" tab within the job settings.
Click on the "Add Transform" button and select "Search/Replace Transform" from the menu.
Configure the First Search/Replace Transform:In the Search/Replace Transform Editor, select the PO_No column from the "Search Column" menu.
In the "Search Value" field, enter the regular expression to find leading zeros. Use ^0+ to match one or more leading zeros.
In the "Replace With" field, enter a placeholder character that you can easily identify and remove later, such as #.Search Value: ^0+
Replace With: #
Save the Transform:Click "Apply" to save the transform.
Add a Second Search/Replace Transform:Click on the "Add Transform" button again and select "Search/Replace Transform" from the menu.
Configure the Second Search/Replace Transform:In the Search/Replace Transform Editor, select the PO_No column from the "Search Column" menu.
In the "Search Value" field, enter the placeholder character you used in the first transform (e.g., #).
In the "Replace With" field, leave it blank to remove the placeholder character.
Here is how you can set it up:Search Value: #
Replace With: (leave this field blank)0 -
0
-
I was able to successfully remove the leading zero using the following:
CASE
WHEN INSTR(fd.PO_NO, ''0'') = 1 THEN SUBSTR(fd.PO_NO, 2)
ELSE fd.PO_NO
END AS PO_No,0
Categories
- All Categories
- 1.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 306 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3K Transform
- 112 SQL DataFlows
- 649 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 787 Beast Mode
- 78 App Studio
- 43 Variables
- 742 Automate
- 187 Apps
- 474 APIs & Domo Developer
- 67 Workflows
- 14 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 406 Distribute
- 117 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 139 Manage
- 136 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 113 Community Announcements
- 4.8K Archive