SQL Server - remove first character
Asked By Lokesh M on 07-Aug-08 03:17 AM
Hi,
I have an sql server table which has few columns and around 1500 records. I wanted to remove only first character in a particular column values.
Thanks
Lokesh
try this...
Vasanthakumar D replied to Lokesh M on 07-Aug-08 03:29 AM
Hi,
here is query for this...
update tableName set filedName = substring(filedName , 2 , len(filedName ) - 1)
You can use SubString for that
Sagar P replied to Lokesh M on 07-Aug-08 03:33 AM
substring(EmpName , 2 , len(EmpName ) - 1)
This will give you empName by removing first char.
Try this.
Best Luck!!!!!!!!!!!
Sujit.
Use this logic...
Atul Shinde replied to Lokesh M on 07-Aug-08 03:35 AM
My table contains:
EmpId EmpName
| 1 |
1A1 |
| 2 |
2B2 |
| 3 |
3C3 |
| 4 |
4D4 |
| 5 |
5E5 |
Query :
Update EMP set EmpName = SUBSTRING(EmpName,2,LEN(EmpName))
Deleting first character
Anonymous anonymous replied to Lokesh M on 07-Aug-08 03:54 AM
UPDATE Names SET FirstName = SUBSTRING(FirstName, 2, LEN(FirstName))
Replace the table name and column name with your desired columns
Vicky replied to Vasanthakumar D on 16-Mar-10 10:28 AM
Thanks!! That worked for me.
Guest replied to Lokesh M on 19-Jul-11 02:31 AM
yeah .. it worked in my issue also.. God bless you
friends, how to this query in mysql, sql server query: select ('+1-' +left( src , 3 )+ '-' + substring( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 )) as src from mytable please give the solution, its urgent. thanks. hi, Please check it out like this. SELECT SUBSTRING('1035442030', 1, 3 SUBSTRING('1035442030', 4, 3) + '-' + SUBSTRING('1035442030', 7, 4) Regards, its not working, , Now i inserted like this 7032442030 but +1-703-244-2030 sql server query: select ('+1-' +left( src , 3 )+ '-' + substring( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 )) as src from mytable please give the query in mysql left ans substring also work in mysql so that query should give you correct result select '+1-' +left
hi, can any one tell how to use substring to break the text. HI try this using System; using System.Windows.Forms; namespace WindowsApplication1 void button1_Click(object sender, EventArgs e) { string str = null; string retString = null; str = "This is substring test"; retString = str.Substring(8, 9); MessageBox.Show(retString); } } } In ASP.Net C# substring string function returns the part of a string starting from the specified starting index. It have two overloads: 1. Substring(int startIndex) 2. Substring(int startIndex, int length) 1st type of Substring overloaded function accepts only single parameter as integer type starting index of the character position
result = emailAddress.Substring(5, 4) hi, string .Substring( startIndex, lenght); for example: string emailAddress = "dv@gmail.com"; string result1 = emailAddress.Substring(5, 4); Response.Write(result1); Result: ail. here string startindex from 5( a) and lenght 4( ail.) Substring method returns a part of a string the index range starts from 0 and in see the following ex and its output string s = "www.eggheadcafe.com" ; string sub = s.Substring(5, 3); Console .WriteLine(sub); Console .ReadLine(); output ggh Hello, Here is simple explanation of Substring functionality. Substring:- The Substring method is an instance method on the string class , which means you must have a
end of post string s = "John Matthew"; Console.WriteLine("First Name:"+ s.Substring(4)); Console.WriteLine("Last Name:"+ s.Substring(0, 4)); Console.ReadLine(); refer below site for more info http: / / dotnetperls.com substring In SQLServer use substring function, it has three parameters 1. original string 2. start index 3. length of the substring to extract refer BOL for more help on substring function. sample: the following SQL statement returns value 'st Va' select substring ( 'Test Value' , 3, 5) One way to search for a string (or substring) in a
hi, can we attached a file , using substring() method and HTML controls . . can u give brief example Thanks hi, The substring() method extracts the characters from a string, between two specified indices, and returns the new characters from a string: <script type = "text / javascript" > var str = "Reena Jain!" ; document.write(str.substring(5)+ "<br / > " ); document.write(str.substring(5, 4)); < / script> Hope this will help you hi. . you cannot do this i think so. . because the substring method is intended to give the substring of the given text between the values providede. . hope this helps you. . . keywords: JavaScript substring, Reena Jain, Substring, characters description: Using Substring()Method hi, can we attached a file , using
Write T-Sql ststement to accomplish this task. Thanks in advance.Please help me. USE SUBSTRING ( value_expression , start_expression , length_expression ) UPDATE TABLENAME SET ICNJUMBER = SUBSTRING(ICNUMBER, 1, 3) +'-' + SUBSTRING(ICNUMBER, 4, 2) + '-' + SUBSTRING(ICNUMBER, 6, 4) Use SubString function for your requirement select case when len(ltrim(rtrim(User_Phone))) = '10' then SUBSTRING(User_Phone, 1, 3)+')'+' '+SUBSTRING(User_Phone, 4, 3)+'-'+SUBSTRING(User_Phone, 7, 4) else User_Phone end AS User_Phone from users Try this and let me
Question: How to retrieve substring from a string in C# to test “ \ n†in the last of the 1) { / / yup, there's a " \ n" in there! } trying to do. To find obtain a substring you use the Substring method of the string. string myString = "test1 \ ntest2 \ ntest3"; string test = myString.Substring(0, myString.IndexOf(" \ n")); / / test = "test1" test = myString.Substring(myString.LastIndexOf(" \ n") + 1); / / test = "test3" test = myString Substring(myString.IndexOf(" \ n") + 1, myString.LastIndexOf(" \ n")- myString.IndexOf(" \ n")); / / test = "test2" Hi Anil, You string: string myString = "This is a Test String \ n"; if (myString.EndsWith(" \ n")) myString = myString.Substring(0, myString.Length - 1); Hope this helps. keywords: C SubString in C QuestionLastIndexOf, class, EndsWith
this 1035442030 but i want insert src field in this format '+1-' +left( src , 3 )+ '-' + substring ( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 ) as phone eg 103-544-2032 where to apply this above format SELECT DATE_FORMAT(calldate, ''''%Y%-%m-%d %H:%I:%s.000'''') as calldate, LEFT(src , 3 )+ ' - ' + SUBSTRING(src , 4 , 3 )+ ' - ' + SUBSTRING(src , 7 , 4 ) as src FROM mytable where DATE_FORMAT(calldate, ''''%Y%-%m-%d %H:%I myproc, Line 14 Operand data type varchar is invalid for subtract operator. LEFT(src , 3 )+ '-' + SUBSTRING(src , 4 , 3 )+ '-' + SUBSTRING(src , 7 , 4 ) as src but i want like this with country code '+1-' '+1-' +left( src , 3 )+ '-' + substring ( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 ) as src please give the solution. SET @sqlQuery = 'SELECT DATE_FORMAT(calldate, ''''%Y%
result = emailAddress.Substring(5, 4) Substring returns part of string from specified index for example string str = " konerushanmukh @yahoo.com"; MessageBox.Show(str.Substring(5, 3)); / / 5 is the start index, 3 is length OutPut ush result = emailAddress Substring(5, 4) IN THIS LINE YOU ARE TAKING SUB STRING FROM emailAddress string. here you if emailaddress: abcdefghj@gmail.com then the result for the statement would be. . . result = emailAddress.Substring(5, 4) result = fghj ; / / becouse when 5 is the index startingposition from left and 4 next 4 characters are taken. . . hope this helps you. . . keywords: Pythonexception, ASP.NET, class, Console, Substring C description: meaning for this statement result = emailAddress.Substring(5, 4) 06-Jun-13 10:11 AM
13 10:31 AM Please check the problem description below SELECT Item.File, Item.Code, SUBSTRING(CONVERT(varchar(8), Search.OrdDate), 5, 2) + ' / ' + SUBSTRING(CONVERT(varchar(8), Search.OrdDate), 7, 2) + ' / ' + SUBSTRING(CONVERT(varchar(8), Search.OrdDate), 1, 4) as orderdate , SUBSTRING(CONVERT(varchar(8), Items.CompleteDt), 5, 2 SUBSTRING(CONVERT(varchar(8), Items.CompleteDt), 7, 2) + ' / ' + SUBSTRING(CONVERT(varchar(8), Items.CompleteDt), 1, 4) as completedate, datediff(DAY, SUBSTRING(CONVERT(varchar(8), Search.OrdDate), 5, 2) + ' / ' + SUBSTRING(CONVERT(varchar(8), Search.OrdDate), 7, 2) + ' / ' + SUBSTRING(CONVERT(varchar(8), Search.OrdDate), 1, 4