[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Check format of field

Posted on 2011-03-09
6
Medium Priority
?
543 Views
Last Modified: 2012-08-14
Hi experts,

Is there a way I can check the format of the an nvarchar field? Meaning I want to make sure the text in this field is XX-XXXX, where X is a number 0-9.

Thanks.
0
Comment
Question by:MAVSS
[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
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:sarabhai
ID: 35083550
Yes you can  used the constraints For this
0
 

Author Comment

by:MAVSS
ID: 35083587
Thanks, sarabhai but I should've clarified. I have to use a query as this will be displayed in a report.
0
 

Author Comment

by:MAVSS
ID: 35084944
Can the format of a field be checked using a SQL query?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 40

Expert Comment

by:lcohan
ID: 35085044
Here - try this:

select * from tablename where columnname like '%[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]%'
0
 
LVL 40

Accepted Solution

by:
lcohan earned 2000 total points
ID: 35085071
sorry you had XX-XXXX - updated below:

create table #t1 (c1 text)
insert #t1 values ('12-1234')
insert #t1 values ('ab-1234')
select * from #t1 where c1 like '%[0-9][0-9]-[0-9][0-9][0-9][0-9]%'
0
 

Author Closing Comment

by:MAVSS
ID: 35085829
Thanks. Used:
where c1 like '[0-9][0-9]-[0-9][0-9][0-9][0-9]' (Did not want to use %%)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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