Removing leading zeros from PO_Number, (using OPENQUERY)
![Roman_K](https://us.v-cdn.net/6032830/uploads/defaultavatar/nZ5X977MOM3Z6.jpg)
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,
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
Categories
- All Categories
- 1.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 304 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3K Transform
- 105 SQL DataFlows
- 644 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 771 Beast Mode
- 74 App Studio
- 43 Variables
- 726 Automate
- 185 Apps
- 466 APIs & Domo Developer
- 61 Workflows
- 14 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 402 Distribute
- 116 Domo Everywhere
- 277 Scheduled Reports
- 9 Software Integrations
- 135 Manage
- 132 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 111 Community Announcements
- 4.8K Archive