If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Selecting multiple values from a INT Field.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 10-28-08, 11:50
Peso Peso is offline
Registered User
 
Join Date: Apr 2007
Posts: 183
Quote:
Originally Posted by pootle flump
Quickest and dirtiest is George's idea.
Most thorough and elegant is XML.
Best compromise is Sean's idea.
1) Let us hope parameters are supplied in same order as concatenated string
2) Let us hope the concatenated string has no more values such as "|1|2|4|"
Reply With Quote
  #17 (permalink)  
Old 10-28-08, 12:19
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Quote:
Originally Posted by Peso
1) Let us hope parameters are supplied in same order as concatenated string
2) Let us hope the concatenated string has no more values such as "|1|2|4|"
Peter, I don't follow what you're saying here...
__________________
George
Twitter | Blog
Reply With Quote
  #18 (permalink)  
Old 10-28-08, 12:47
Thrasymachus Thrasymachus is offline
SQL Server Street Fighter
 
Join Date: Nov 2004
Location: Down The Rabbit Hole
Posts: 7,979
Quote:
Originally Posted by Peso
1) Let us hope parameters are supplied in same order as concatenated string
2) Let us hope the concatenated string has no more values such as "|1|2|4|"
on number 1, I think he misunderstands. Mine simply solves the problem of a variable number of parameters that fit into a IN (1,2,3) scenario.

If the concatenated string pertains to various parameters matching different fields, yeah my approach is stupid.
__________________
software development is where smart people go to waste their lives
Reply With Quote
  #19 (permalink)  
Old 10-28-08, 12:53
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I'm still lost
__________________
George
Twitter | Blog
Reply With Quote
  #20 (permalink)  
Old 10-29-08, 04:05
MrRalphMan MrRalphMan is offline
Registered User
 
Join Date: Jul 2007
Posts: 50
Quote:
Originally Posted by Peso
Do the binary calculation on client side and pass value to stored procedure?

Code:
-- Prepare sample data
DECLARE	@Sample TABLE
	(
		data VARCHAR(20),
		binVal INT
	)

INSERT	@Sample
SELECT	'Peso', 15 UNION ALL
SELECT	'dbForums', 9 UNION ALL
SELECT	'SQL Server', 5 UNION ALL
SELECT	'Microsoft', 3

-- Prepare user supplied binary value
DECLARE	@param INT

-- Calculate the binary value for bit 1 and 4 set at client side. Value is 9.
SET	@param = POWER(2, 1 - 1) + POWER(2, 4 - 1)

-- Search the table for exact match
SELECT	data
FROM	@Sample
WHERE	binVal & @param = @param

-- Search the table for match on any of the given bits
SELECT	data
FROM	@Sample
WHERE	binVal & @param > 0
Dude, I like this, I like this a lot.

What is the & operation between the two INT's to have this work?

Paul.
Reply With Quote
  #21 (permalink)  
Old 10-29-08, 05:16
Peso Peso is offline
Registered User
 
Join Date: Apr 2007
Posts: 183
It is a binary AND in T-SQL.
Reply With Quote
  #22 (permalink)  
Old 11-01-08, 04:08
MrRalphMan MrRalphMan is offline
Registered User
 
Join Date: Jul 2007
Posts: 50
Cheers, still don't quite understand it, but it works so I'm happy.

Thanks.
Reply With Quote
  #23 (permalink)  
Old 03-14-10, 06:08
MrRalphMan MrRalphMan is offline
Registered User
 
Join Date: Jul 2007
Posts: 50
Sorry for bumping a rather old thread, but this doesn't seem to work well for large number of boolean values...

Ie This works fine when I have a low number, but once we have a larger number (30ish), the int values grow to silly sizes and the join to the table holding the string values impacts performance in a silly way.

With the join to the large boolean int value a full query takes about 90 seconds, with it joined to the table key fields, int starting at 1 and increasing by 1, it takes 20 seconds.

I have gotten around this by passing the seperate values searched for as an XML string, but would like to know the reason behind this performance hit?

Cheers,

Paul.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On