I have a query where I'm pulling in a check number from the database. The return value needs to always be 9 characters exactly. Most of the check numbers are only 6 characters, so I want to prepend 0s to to the string to ensure it is always exactly 9 characters. Since the check numbers can vary in length, it will be a different number of 0s for each one. What's the most efficient way to do this?
Prepend 0s to string (to specific length)
805 Views Asked by Jana At
1
There are 1 best solutions below
Related Questions in SQL
- SQL schema for a fill-in-the-blank exercise
- Hibernate: JOIN inheritance question - why the need for two left joins
- What's supposed to be the problem in this query?
- Compare fields in two tables
- How to change woocomerce or full wordpress currency with value from USD to AUD
- Dynamic query creation with Array like implementation
- SQL query to get student enrolled in this month in a course - Moodle
- SQL LAG() function returning 0 for every row despite available previous rows
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Use row values from another table to select them as columns and establish relations between them (pivot table)
- SQL: Generate combination table based on source and destination column from same table
- how to use system's environnement variables in sql script
- PHP fetchAll on JOIN
- Multitable joining in Sql
- How to display name starting from 'z' by using BETWEEN cmd only?
Related Questions in STRING
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- JSON Body is Not Passing Certain Strings
- Regex to match repeated substring in Google Sheets
- Find the sum of the numbers in the sequence
- Hello, how can I use a block parameter of withstyle parameter when we create a annotated string in jetpackpack compose
- How to convert an HTML string to an escaped one?
- Quintic Number Number Counting Hash Function
- From Buffer("string", "hex) to string JS
- Calling ToString with a nominated format returns Char rather than String
- How to update an already existing array by accessing it by a variable with the exact same name assigned to it
- Why does \b not interpreted as backslash in this regular expression
- Python: why aren’t strings being internalized if they are received from ints by using str()?
- If the element(s) in the first list equal element(s) of the second list, replace with element(s) of the third list
- About Suffix Trees features
Related Questions in LOOPS
- how to create Infinite Upgrades in a clicker game
- How do I write a loop in F# such that the value of a in the previous step is now assigned to b and so on?
- Algorithm for finding a subset of nodes in a weighted connected graph such that the distance between any pair nodes are under a postive number?
- Having issues getting the correct output with hi low game
- Pine Script: Loop Through Input Price levels & set Alerts for Each Price
- How to iteratively create matrices/vectors from columns/unique row values of dataframe, and pass them to subsequent code?
- Loop through multiple levels of a variable in R
- Matching hundreds non-adjaccent keywords in large text corpus in Python
- Reversing a number in Python
- How do I add a loop into this macro to repeat 'x' amount of times
- Optimising my C loop for a combinatorial problem
- Iterate over items in one array and groups of items in second array
- Cannot borrow variable as mutable within loop
- Taking all numbers from an arraylist and outputting only the even numbers
- Iterating through a string of long characters R
Related Questions in PREPEND
- Zapier: Prepend to a value if value exist
- Add rewrite rule in .htaccess
- ionic in-app browser adding "http" protocol to play store intent url
- Prepend string before each character of another string
- Powershell Prepend Header File to Huge Non-csv Data File Without Creating 3rd File
- Is there a efficient way to prepend a list from items from another list?
- Go | efficient and readable way to append a slice and send to variadic function
- Back-reference when preprend using sed linux command
- Prepend and append slides with swiper.js
- How to use insertBefore and appendChild with a jQuery AJAX server side rendered html result
- Why prepend does trigger once in a loop?
- Using Javascript Template Literals With The prepend() Method
- jQuery prepend() stringifies argument
- sed prepend and add double-quote conditionnally
- How to prepend scss files in Vue3 + dart-sass?
Related Questions in STRING-LENGTH
- How i can check the full length of number even if it includes zeros?
- In Tcl, why is the string length of an empty string 1, not 0?
- StringLengthAttribute does not enforce length
- C++ wrong std::string length when using constructor from "empty" char array
- Strlen function giving wrong length when there are non-english characters in string
- How to get terminating length in length of string in java?
- I get an error "TypeError: object of type 'Number' has no len()" in my laptop or any other system while the same code run fine in my system
- Some test cases failing while trying to implement palindrome of a string in C without using built in functions
- ReactJS Uncaught TypeError: Cannot read properties of undefined (reading 'length')
- The "randomword" can not access the .length method. Why is that?
- Java Stream API to find a lenth of object (the length of toString())
- While condition in python doest stop the loop when true
- c++, How to display an error if user inputs more than one char
- Oracle - Why I can't exclude rows where length(listagg(somecolumn)) > xxx
- how create a method that will only accept user input if its 1 character string long or else, print error
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If they're always between 6 and 9 digits, the easiest (and probably best) way to go is using CASE.
EDIT
In case the original values are numbers (
int), try something like this:Take a look at the this SQL Fiddle.