Solved

SQL query help with error

Posted on 2014-02-21
6
172 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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