Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query

Author  Topic 

cmorgan007
Starting Member

1 Post

Posted - 2011-05-17 : 09:59:02
My technical guy is away and I'm stuck. I need to run an SQL Query on a particular table. When in the table instead of opening if I go to 'open table- query' I need to remove the first character from a column. The column is called 'number' The column currently contains numbers i.e 07900666666 and I wish to remove the first number '0'.

can some kind soul send me the query that will achieve this.

Thanks

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-05-17 : 10:13:12
UPDATE yourTable
SET NumberColumn = CASE LEFT(NumberColumn ,1) WHEN '0' THEN SUBSTRING(NumberColumn,2,LEN(NumberColumn)-1) END

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-05-17 : 10:23:50
I would say your number column is defined as varchar(n)

Can you post the DDL?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-05-17 : 10:26:30
slight problem there


DECLARE @t table([number] varchar(25))

INSERT INTO @t([number])
SELECT '07900666666' UNION ALL
SELECT '7900666665' UNION ALL
SELECT '007900666667'

SELECT CHARINDEX('0',[number]) FROM @t

SELECT CASE LEFT([Number] ,1) WHEN '0' THEN SUBSTRING([Number],2,LEN([Number])-1) ELSE [Number] END
FROM @t


what if there is more than 1 leading 0



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -