Solved

SQL query help with error

Posted on 2014-02-21
6
170 Views
Last Modified: 2014-02-21
Ok I am investigating a query that someone developed for my company:

CAST(CAST(SUBSTRING(KeyField, 7, 10) AS BIGINT) AS varchar) AS OrderLineLink

The keyfield column has data such as....
0000230008    retult....    8
0000290004    result....   4

but now im getting data in the Keyfield such as...

000023AER8

This is obv causing a crash. If the conversion is not possible how can I get it to use null?
0
Comment
Question by:deanlee17
  • 3
  • 3
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39876329
try only

SUBSTRING(KeyField, 10, 10) AS OrderLineLink
0
 

Author Comment

by:deanlee17
ID: 39876338
Can you explain how its working?
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39876348
SUBSTRING(KeyField, 10, 10)

this will give you last charater in the given string

your string have length 10 , this formula provide last charater of it
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:deanlee17
ID: 39876364
Actually, sorry to change the question slightly, but ive just noticed it needs to start far right and move left until it hits aa zero, so....

0000290004  = 4
0000290014  = 14
0000290144  = 144

Thank you.
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 39876432
try this

charIndex( '0',Reverse(KeyField)),Substring (KeyField ,Len(KeyField)- charIndex( '0',Reverse(KeyField))+2,Len(KeyField))
0
 

Author Comment

by:deanlee17
ID: 39876447
Thank you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to deploy to IIS 7 on 2008R2 server with DUO 2-step login? 2 37
Error in page 3 46
C# Single Form 8 29
Visual Studio TFS - how do I check in my code? 2 29
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now