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
- Can MVC.NET prevent SQL-injection at razor or controller level?
- SQL server not returning all rows
- When dealing with databases, does adding a different table when we can use a simple hash a good thing?
- Creating a parametrized field name for a SELECT clause
- Combine two rows based on common ID
- Column displays each count
- Slick query for one to optional one (zero or one) relationship
- Aggregate and count in PostgreSQL
- MAX and GROUP BY - SQL
- SQL statement for a tricky 2 table query
- How to create nested selects with sql?
- Pull and push data from and into sql databases using Excel VBA without pasting the data in Excel sheets
- Best Practice for adding columns to a Table in Oracle database
- SQL FIFO STACK using two tables
- SQL Query - Order by String (which contains number and chars)
Related Questions in STRING
- SML - Find same elements in a string
- match hex string with list indice
- How can I determine the index of the same set of characters between two strings that are of different lengths?
- String.replace() isn't working like I expect
- How to do a case-insensitive string comparison?
- Trying to save an np array with string and floats, but getting a error
- String replace with integer not working
- How to calculate a length of array with out using library
- Java replace every Nth specific character (e.g. space) in String
- Split the strings into two parts Python
- Perl Regex: Merge multiple one-character substrings
- Squid S2275 does not know about format string argument indexes
- more efficient way of remove a few characters from the end of a string
- python member str performance too slow
- String.split() not behaving in android
Related Questions in LOOPS
- Java catch the ball Game
- Looping over defined array elements in Fortran
- Loop with equation for upper limit
- Extract series of observations from dataframe for complete sets of data
- Split a large query (2 days) into pieces to increase the speed in Postgres
- Java filewriter only writing last line to file?
- For loop inside if statement will not run and I'm not sure why
- How to change Boolean array to double array
- Recent development in recoding repeated variables in R?
- Service is reporting "service has reported an invalid current state 0."
- using a for loop to compare lists
- mutating method sent to immutable object' in nsmutablearray
- Efficiency penalty of initializing a struct/class within a loop
- the difference between zip and enumerat in for loop?
- How to loop each array for Counter function inside a list using Python?
Related Questions in PREPEND
- Python match a regex with specified exceptions
- Diary Matlab :: Latest messages on top of the text file instead of append to bottom of file
- Add object to start of dictionary
- prepend to a list
- Setting a user verification with auto_prepend Joomla
- Pre-pend required number of characters in Excel
- How can I keep this appended DIV in place after "price" changes?
- Prepend a button in each list element of unordered list using jQuery
- How can I prepend table headers to html table that was created using getJSON() function in jQuery
- how to append a row to a table with jquery in second position?
- C# Prepend 40 bytes onto stream
- How do I prepend string to a field value in MySQL?
- Matlab: Prepend string to a cell array of strings
- How to prepend message to Javascript event queue? (Canceling long running methods)
- issues with jquery prepend
Related Questions in STRING-LENGTH
- How to calculate a length of array with out using library
- Concatenation of strings array issues in Python: Str(ArrayOfString[1])+" "+Str(ArrayOfString[2]) doesn't seem to work
- Issues With length() And Multiples Of 3
- Subclass Method That Generates Different Message If Input Len > 20
- How to get range of textField text till 6 characters?
- How to not count special character and vowels occurences in string length using user input
- Read File Line by Line and Count in Matlab;save in one string
- How to format the string to certain length and show it new line in an array using PHP
- comparing identical strings returns false
- JQuery string length
- In C, sort array of strings by string length
- Why is the size of my string changing? (C)
- Find out if a value is within a range with one if clause in PHP?
- How to count the number of terms in a table with postgresql?
- limiting characters after dot - java
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 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.