Solved

Formatting CASE statement from VARCHAR to BIGINT

Posted on 2007-11-27
4
753 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Expert Comment

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

Accepted Solution

by:
deroby earned 125 total points
ID: 20356981
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
ID: 20357959
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
ID: 20357979
I found it's another part of the query that's not working (not shown). Thanks for confirming the above worked.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

695 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