We help IT Professionals succeed at work.
Get Started

Casting varchar as int

646 Views
Last Modified: 2011-10-19
Hi Experts!

I have to create a search query for various fields.  The search string is type varchar and all of the fields in a table are varchars of different lengths.  The problem is two fields FEIN and ERN store mostly numeric data.  I cannot change the data types and I have tried to cast the varchar as an int in my where clause but I get an error.   An example of a FEIN could either be 11-1111111 or 111111111.  ERN are always 7 digits. Can anyone assist me?
Thanks
Miracle by Design
WHERE ((Cast(FEIN as int)) = cast(@Criteria as int) and a.JTAppID is not null)

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 14 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE