Solved

SQL query help with error

Posted on 2014-02-21
6
169 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

21 Experts available now in Live!

Get 1:1 Help Now