View previous topic :: View next topic
|
Author |
Message |
Khwairakpam Raju Singh
New User
Joined: 05 Dec 2007 Posts: 29 Location: Bangalore
|
|
|
|
Hi All,
Could anyone help me out to form a SQL query for the following requirement?
I have a requirement where in I have to set the value of a column to space if the length of value present in the field is not equal to 2.
e.g.: the Value present in the field (say col_A) of a table (say tab_A) is 'A03' or 'A' then I have to update the value as space. On the other hand if the value is 'AB' (2 byte length). Then I have to keep as it is.
Please suggest me how to do in SQL. Thanks in advance. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Is this column defined as varchar? |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
if col_a is varchar then
update ... where length(col_a) <>2
else
update ... where length(strip(col_a)) <> 2 (if you define "length of value" as number of characters without trailing spaces ) |
|
Back to top |
|
|
Khwairakpam Raju Singh
New User
Joined: 05 Dec 2007 Posts: 29 Location: Bangalore
|
|
|
|
Oh!! Due to some misunderstanding, I was trying with LEN(), and I got and error.
now its working with the LENGTH() fuction :-) Thanks a lot for you help |
|
Back to top |
|
|
|