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
 Deleting Numbers after hyphen

Author  Topic 

Dahlen
Starting Member

3 Posts

Posted - 2012-04-24 : 07:15:57
Hello everyone,

I am very new to SQL and am needing assistance in deleting the values after a hyphen. For example: 604-0 should only be 604.

Can anyone please advise? And also, can anyone recommend a book for new SQL users specifically in understanding how to retrieve data?

I've read SQL for Dummies but it is quiet confusing..
Any help is truly appreciated!

D

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-24 : 07:24:28
[code]SELECT STUFF(YourCol,CHARINDEX('-',YourCol),LEN(YourCol),'');[/code]
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-24 : 07:28:04
Two beginner level books that I like are:

http://www.amazon.com/Beginning-Microsoft-Server-Programming-Programmer/dp/0470257016/ref=sr_1_1?s=books&ie=UTF8&qid=1335266785&sr=1-1
http://www.amazon.com/Microsoft%C2%AE-Server%C2%AE-T-SQL-Fundamentals-PRO-Developer/dp/0735626014/ref=sr_1_sc_2?ie=UTF8&qid=1335266735&sr=8-2-spell

Also, a few helpful sites, all from DonAtWork's signature line:

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Dahlen
Starting Member

3 Posts

Posted - 2012-04-24 : 07:44:45
Thank you Sunitabeck..

I used your Syntax and getting an error..And not sure what I am doing incorrectly.. Error shows: Incorrect Syntax near ')'

Select TOP 10 LOANACCTNUM, PROCBRANCH,
CHARINDEX ('-',PROCBRANCH), len (PROCBRANCH),'');
FROM dbo.SM_PrimeExtShort
WHERE FundDt > '3/1/2012'

Can you please help?
Go to Top of Page

Dahlen
Starting Member

3 Posts

Posted - 2012-04-24 : 07:46:54
Thank you, I am learning on my own time and am at a lost with SQL.. I will look at these and order! Thank you for the links as well!!

D

quote:
Originally posted by sunitabeck

Two beginner level books that I like are:

http://www.amazon.com/Beginning-Microsoft-Server-Programming-Programmer/dp/0470257016/ref=sr_1_1?s=books&ie=UTF8&qid=1335266785&sr=1-1
http://www.amazon.com/Microsoft%C2%AE-Server%C2%AE-T-SQL-Fundamentals-PRO-Developer/dp/0735626014/ref=sr_1_sc_2?ie=UTF8&qid=1335266735&sr=8-2-spell

Also, a few helpful sites, all from DonAtWork's signature line:

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-24 : 08:43:11
quote:
Originally posted by Dahlen

Thank you Sunitabeck..

I used your Syntax and getting an error..And not sure what I am doing incorrectly.. Error shows: Incorrect Syntax near ')'

Select TOP 10 LOANACCTNUM, PROCBRANCH,
CHARINDEX ('-',PROCBRANCH), len (PROCBRANCH),'');
FROM dbo.SM_PrimeExtShort
WHERE FundDt > '3/1/2012'

Can you please help?

Change it to this:
Select TOP 10 LOANACCTNUM, PROCBRANCH, 
STUFF(PROCBRANCH,CHARINDEX ('-',PROCBRANCH), len (PROCBRANCH),'')
FROM dbo.SM_PrimeExtShort
WHERE FundDt > '3/1/2012'
Go to Top of Page
   

- Advertisement -