473,427 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

SQL Trim problem

121 100+
Hello All,
Problem i am facing is , i need to add some zero's to the user input. if user inputs 012345, i need to save 00012345 (total 8 characters), which can be done by
Expand|Select|Wrap|Line Numbers
  1. CAST(REPLACE(STR(VarcharValue,8),' ','0') as Varchar(8))
but this code breaks when user enter's any string with alphanumeric characters. Is their any way i can do like if input has any alphanumeric character in it, ignore this replace query else do this?

just for info: whole data is database is stored in varchar(8), which can be integer value with leading 0 if less than 8 characters to make it to 8 characters OR some varchar value.

Any help will be appreciated

Regards
Jay
Jul 7 '10 #1

✓ answered by jvskarthick

Hi,

Check with the below given option.

DECLARE @STR VARCHAR(8)
SELECT @STR = '01105'
--SELECT ISNUMERIC(@STR)
SELECT CASE WHEN ISNUMERIC(@STR) = 1 THEN RIGHT(('00000000' + @STR), 8) ELSE RIGHT(('00000000' + @STR), 8) END

Thanks,
JK

2 2221
Hi,

Check with the below given option.

DECLARE @STR VARCHAR(8)
SELECT @STR = '01105'
--SELECT ISNUMERIC(@STR)
SELECT CASE WHEN ISNUMERIC(@STR) = 1 THEN RIGHT(('00000000' + @STR), 8) ELSE RIGHT(('00000000' + @STR), 8) END

Thanks,
JK
Jul 7 '10 #2
jay123
121 100+
@jvskarthick
on the spot, really appreciated.

Thanks
Jul 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jan Bols | last post by:
Whenever I execute TRIM(' ')in a stored procedure or trigger, I get an ORA-03113 error. I have an oracle db 8.1.7.0.1 Enterprise edition installed on a linux-Mandrake 9.1. EXEMPLE: I...
2
by: Stephen | last post by:
I have the following code working in order to create an array list and populate a datagrid however everytime i click my button the first item in the array and the first row in the datagrid are...
3
by: Ronin | last post by:
Hi i am using following code which extracts information from XML file and creates an instance of class which it adds to hash table. problem is i am unable to extract information from hashtable :...
4
by: Stephen | last post by:
I have the following code working in order to create an array list and populate a datagrid however everytime i click my button the first item in the array and the first row in the datagrid are...
8
by: sengkok | last post by:
I have develop a smart card device reading and writing program, but I am facing a problem that when I read the value from the smart card, I get "A19\0 \0\0\0", (actually I have store the value A19...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
22
by: Terry Olsen | last post by:
I have an app that makes decisions based on string content. I need to make sure that a string does not contain only spaces or newlines. I am using the syntax 'Trim(String)" and it works fine. I...
2
by: DavidAM | last post by:
Hello, In my code I use the following command: me.richtextbox1.text = me.richtextbox1.text.trim By doing this I lose al my text formatting, it seems that by setting the text property of a...
3
by: helraizer1 | last post by:
Hey folks, yet again. if ($back == "m") //$back is a value pulled from a db; that works perfectly. { $wid = $rowing; $hei = $rowing; createthumb("660x240background2.gif", "./user/" ....
23
by: ryna | last post by:
Desperately need help.... here's the snippet of my code that im trying to solve since last week... icePayment.aspx If (Left(Request.Form("return_url"), 7) <> "http://") Then errorInput =...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.