• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 757
  • Last Modified:

Formatting CASE statement from VARCHAR to BIGINT

My case statement below formats well, however, I'd like to convert the varchar output into a bigint, but I'm not sure where I'm going wrong. I receive the error message: Error converting data type varchar to bigint.

SET @StorePhone = '(123)456-7891'

            StorePhone =      CASE SUBSTRING(@StorePhone, 1,1) WHEN '('
                                    THEN 111111111
                                    ELSE 222222222 END

  • 2
1 Solution
Aneesh RetnakaranDatabase AdministratorCommented:
what in case the phone number is  of the format  999-99999-999
Works fine here...

How did you declare the @StorePhone variable ?? Should be a varchar if the first thing you want to do is store  '(123)456-7891' into it
barnescoAuthor Commented:
It's a varchar (to accept all those parenthesis and dashes),  but the table is a bigint, which is why I'm converting it.
barnescoAuthor Commented:
I found it's another part of the query that's not working (not shown). Thanks for confirming the above worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now