Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Use of the "Like" Clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-16 : 07:53:56
Rusty writes "I have used the "Like" clause to filter text fields based on a character mask. We currently have some ID numbers stored in a character field. So when I apply an Like mask of "51%", I get fields equal 51, 510, 5100, 51989, 519, 512, etc...

I am planning on creating a new table, but I was thinking of storing the ID numbers as integers, not characters. Will I still be able to use a Like mask to find all records in the example described above? Is it possible to do Like filters with numeric fields?"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 07:56:46
Like operator will very well work on integers also. Apply the same query

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-02-16 : 08:43:18
quote:
Originally posted by AskSQLTeam

Rusty writes "I have used the "Like" clause to filter text fields based on a character mask. We currently have some ID numbers stored in a character field. So when I apply an Like mask of "51%", I get fields equal 51, 510, 5100, 51989, 519, 512, etc...

I am planning on creating a new table, but I was thinking of storing the ID numbers as integers, not characters. Will I still be able to use a Like mask to find all records in the example described above? Is it possible to do Like filters with numeric fields?"



Here is my obligitory normalization rant (you all knew it was coming):

Please consider re-designing your database in a normalized manner so that you store multiple values for that column in multiple ROWS in a related table. this way, you can use regular SQL statements to retrieve and manipulate your data very easily, you can declare foreign key constraints to have data integrity, and you will not have to worry about inefficent and sloppy workarounds like this one.

End of rant.

EDIT: almost forgot the link:

http://www.datamodel.org/NormalizationRules.html
Go to Top of Page
   

- Advertisement -