.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 9th, 2008, 07:52 AM
WilliamL WilliamL is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 9 WilliamL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 35 m 31 sec
Reputation Power: 0
Compare arrays in SQL

yo, i want to pick rows from a table with the criteria that at least one of the element in a string that is comma separated is the same as at least one of the element in a field with the same kind of string.

for example:

i insert the string "red, green, blue"

in the table there is:

RowID MyStringValue
1 | "red,white,black"
2 | "white,yellow,gray"
3 | "black,blue,green"

i want with a select statement get row 1 and 3, but not 2. In vb.net i would have done something like this.

Code:
Public Shared Function CompareValues(ByVal conditions As String, ParameterArray sourcedata As String) As Boolean
For Each s As String In sourcedata
  For Each t As String In conditions.Split(",")
  If s = t Then Return True
  Next
Next
Return False
End Function


How do i write a function like that in SQL, that i later on can use in my WHERE-statement. i have full access to the database and all type of stored procedures and etc is no worry. btw, i work in mssql 2005

Reply With Quote
  #2  
Old May 10th, 2008, 11:42 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400

Reply With Quote
  #3  
Old May 15th, 2008, 12:46 PM
macu macu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 12 macu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 31 sec
Reputation Power: 0
Or, you could rethink your table design, e.g. if you had a parent table and a child table that contained your colours, something like:

CREATE TABLE ParentTable(ID int identity(1, 1) not null, SomeOtherColumn int)

CREATE TABLE ChildTable(ParentTableID int not null, Colour varchar(10) not null) --not showing foreign key...

Then your stored proc could just do something like insert into a temp table and do a straight forward join to the child table and pull back all parent id's (or parent rows if required). This would be super quick and you may find other benefits with having your colour data split out like this.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > Compare arrays in SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway