SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Binary Field Search
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Zath
Constraint Violating Yak Guru

USA
282 Posts

Posted - 07/16/2007 :  14:42:30  Show Profile  Visit Zath's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 07/16/2007 :  14:45:07  Show Profile  Visit dinakar's Homepage  Reply with Quote
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

USA
282 Posts

Posted - 07/16/2007 :  14:58:57  Show Profile  Visit Zath's Homepage  Reply with Quote
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

Edited by - Zath on 07/16/2007 14:59:28
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

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



CODO ERGO SUM

Edited by - Michael Valentine Jones on 07/16/2007 15:11:43
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000