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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Binary Field Search

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2007-07-16 : 14:42:30
Usually to search a varchar field, this is done:

IF NOT @manufacturer IS NULL SET @manufacturer = '%' + LTRIM(RTRIM(@manufacturer)) + '%';
--use this for searching table.

Now, I have a binary field that stores an ip address called @ip.
@ip will also be binary.

How can I set this up to search it's field called ipAddress?

Thanks,

Zath

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-16 : 14:45:07
Can you post some sample data in the table? and how your @IP values might look like?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2007-07-16 : 14:58:57
Procedure dbo.someSearch

@ip binary(4) = null
AS
BEGIN
-- clean data
--IF LTRIM(RTRIM(@ip)) = '' SET @ip= NULL;

-- set us up for the searches
--IF NOT @ipIS NULL SET @ip= '%' + LTRIM(RTRIM(@ip)) + '%';

SELECT ipAddress FROM someTable WHERE ipAddress LIKE @ip

the commented out lines above is where I'm not sure how to set this up to search a binary field using a binary.

Zath
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-16 : 15:10:51
Since you are passing in an IP address, why wouldn't this work?
SELECT ipAddress FROM someTable WHERE ipAddress = @ip



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -