Solved

Check format of field

Posted on 2011-03-09
6
523 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

20 Experts available now in Live!

Get 1:1 Help Now