?
Solved

sql left and charindexfunction

Posted on 2011-09-20
3
Medium Priority
?
239 Views
Last Modified: 2012-05-12
Can anyone please tell why this is erroring out

select            
case  
when isnumeric(left('2022AVEQENSLEY',case when charindex(char(32),'2022AVEQENSLEY')
            =0 then 2
            else charindex(char(32),'2022AVEQENSLEY') end -1)) = 1
then left('2022AVEQENSLEY',charindex(char(32),'2022AVEQENSLEY')-1)
else replace(replace('2022AVEQENSLEY',char(32),''),'.','')
end
      
0
Comment
Question by:baylar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 36571124

This returns 0
charindex(char(32),'2022AVEQENSLEY')

Then you actually reduce it by -1
else charindex(char(32),'2022AVEQENSLEY') end -1))

You can not pass -1 to CHARINDEX function
0
 
LVL 29

Accepted Solution

by:
QPR earned 2000 total points
ID: 36571125
0
 

Author Closing Comment

by:baylar
ID: 36571246
Awesome works the way I want.
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question