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.
| 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] |
 |
|
|
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-1http://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-spellAlso, 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 |
 |
|
|
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_PrimeExtShortWHERE FundDt > '3/1/2012'Can you please help? |
 |
|
|
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!! Dquote: 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-1http://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-spellAlso, 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
|
 |
|
|
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_PrimeExtShortWHERE 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_PrimeExtShortWHERE FundDt > '3/1/2012' |
 |
|
|
|
|
|
|
|