PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Search for specific length string in column
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Search for specific length string in column

Réponse
 
LinkBack Outils de la discussion
Vieux 14/09/2007, 15h19   #1
mike@mcarlson.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Search for specific length string in column

SQL 2000.

I need a query that will search a field in the table that is 14
characters long and begins with a number.

I have a client that was allowing people to store credit card numbers,
plain text, in an application. I need to rip through the table and
replace every instance of credit card numbers with "x" and the last 4
digits. I got the replace bit going, but I am stuck on how to search
for a string in a field of a specific length.

Any ideas?

Thanks,
--Mike

  Réponse avec citation
Vieux 14/09/2007, 18h58   #2
Jack Vamvas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Search for specific length string in column

select * from MyTable where len(reference) = 2 and
SUBSTRING (reference ,1 ,1 ) IN ('0','1','2','3','4','5','6','7','8','9')

you could expand and use the ISNUMERIC()


--

Jack Vamvas
___________________________________
Need an IT job? http://www.ITjobfeed.com




<mike@mcarlson.net> wrote in message
news:1189779565.603908.70530@19g2000hsx.googlegrou ps.com...
> SQL 2000.
>
> I need a query that will search a field in the table that is 14
> characters long and begins with a number.
>
> I have a client that was allowing people to store credit card numbers,
> plain text, in an application. I need to rip through the table and
> replace every instance of credit card numbers with "x" and the last 4
> digits. I got the replace bit going, but I am stuck on how to search
> for a string in a field of a specific length.
>
> Any ideas?
>
> Thanks,
> --Mike
>



  Réponse avec citation
Vieux 14/09/2007, 19h54   #3
Hugo Kornelis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Search for specific length string in column

On Fri, 14 Sep 2007 07:19:25 -0700, mike@mcarlson.net wrote:

>SQL 2000.
>
>I need a query that will search a field in the table that is 14
>characters long and begins with a number.


Hi Mike,

WHERE LEN(YourColumn) = 14
AND LEFT(YourColumn, 1) LIKE '[0-9]'

>I have a client that was allowing people to store credit card numbers,
>plain text, in an application. I need to rip through the table and
>replace every instance of credit card numbers with "x" and the last 4
>digits. I got the replace bit going, but I am stuck on how to search
>for a string in a field of a specific length.


Are you sure you need to check only the first character for numeric? All
my credit cards have only numbers. To test for length 14 and only
numbers, you can change the above to

WHERE LEN(YourColumn) = 14
AND YourColumn NOT LIKE '%[^0-9]%'

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
  Réponse avec citation
Vieux 14/09/2007, 22h38   #4
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Search for specific length string in column

Hugo Kornelis (hugo@perFact.REMOVETHIS.info.INVALID) writes:
> Are you sure you need to check only the first character for numeric? All
> my credit cards have only numbers. To test for length 14 and only
> numbers, you can change the above to
>
> WHERE LEN(YourColumn) = 14
> AND YourColumn NOT LIKE '%[^0-9]%'


And my two credit-cards have 16-digit numbers...


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
  Réponse avec citation
Vieux 15/09/2007, 09h25   #5
Hugo Kornelis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Search for specific length string in column

On Fri, 14 Sep 2007 21:38:51 +0000 (UTC), Erland Sommarskog wrote:

>Hugo Kornelis (hugo@perFact.REMOVETHIS.info.INVALID) writes:
>> Are you sure you need to check only the first character for numeric? All
>> my credit cards have only numbers. To test for length 14 and only
>> numbers, you can change the above to
>>
>> WHERE LEN(YourColumn) = 14
>> AND YourColumn NOT LIKE '%[^0-9]%'

>
>And my two credit-cards have 16-digit numbers...


Heh! So has mine - I didn't even think of that while posting my reply.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
  Réponse avec citation
Vieux 16/09/2007, 06h20   #6
--CELKO--
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Search for specific length string in column

>> I have a client that was allowing people to store credit card numbers in plain text, in an application. I need to rip through the table and replace every instance of credit card numbers with "x" and the last 4 digits. <<

You might want to learn the difference between a field and column
before you write anymore SQL -- like what a constraint is. I assume
that youmeant 16 digits, broken into groups of 4 digits.

UPDATE Foobar
SET creditcard_nbr
= 'xxxx-xxxx-xxxx-" + SUBSTRING( creditcard_nbr,13, 16);

Having done this, put all of this in the DDL. Mop the floor,but fix
the leak!!

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10388 seconds with 14 queries