Solved

Formatting CASE statement from VARCHAR to BIGINT

Posted on 2007-11-27
4
751 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to just get time from a date 6 31
Index and Stats Management-Specific tables 8 19
SQL Group By Question 4 18
SQL Recursion 6 16
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

791 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