Solved

Formatting CASE statement from VARCHAR to BIGINT

Posted on 2007-11-27
4
749 Views
Last Modified: 2008-02-01
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

Thanks
0
Comment
Question by:barnesco
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
what in case the phone number is  of the format  999-99999-999
0
 
LVL 11

Accepted Solution

by:
deroby earned 125 total points
Comment Utility
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
0
 

Author Comment

by:barnesco
Comment Utility
It's a varchar (to accept all those parenthesis and dashes),  but the table is a bigint, which is why I'm converting it.
0
 

Author Comment

by:barnesco
Comment Utility
I found it's another part of the query that's not working (not shown). Thanks for confirming the above worked.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

763 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

10 Experts available now in Live!

Get 1:1 Help Now