Solved

sql left and charindexfunction

Posted on 2011-09-20
3
218 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
3 Comments
 
LVL 32

Expert Comment

by:ewangoya
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 500 total points
ID: 36571125
0
 

Author Closing Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

770 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