Solved

Check format of field

Posted on 2011-03-09
6
526 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
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 39

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 39

Accepted Solution

by:
lcohan earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dimension table indexes 8 28
why sql server only update some statistics in the database ? 3 24
New to SSRS, extremely slow running report. 8 20
While in ##Table - Help 4 17
Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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