Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Parse String

Started 1 month, 4 weeks ago by mankish
I have a table with a column called members and in it the rows are like ID Members ---------- ----------- 1 1\2\3 2 2\3\4 3 2\3 4 1\5 I have a reference table where 1 = father, 2= mother, 3=sister, 4=brother, 5=grapnparents. Is there any way I can query the memebers table like this ID ...
Site: Tek-Tips Forums  Tek-Tips Forums - site profile
Forum: Microsoft SQL Server: Programming  Microsoft SQL Server: Programming - forum profile
Total authors: 5 authors
Total thread posts: 8 posts
Thread activity: no new posts during last week
Domain info for: tek-tips.com

Other posts in this thread:

chapuchi30 replied 1 month, 4 weeks ago
use the inner join sentence, something like select a.id,b.members from table1 a inner join table2 b on a.members=b.id

markros replied 1 month, 4 weeks ago
You need to use splitting function, such as fnSplit and then you would concatenate results into one string back. See the first part of the task CODE declare @Members table (MemberID int identity(1,1), member varchar(100)) insert into @Members values ('1\2\3'), ('2\3\4'), ('2'),('1\5') declare @Delimiter varchar(10) = '\' select X.*, Ref.Description from (select M.*, Value from @...

markros replied 1 month, 4 weeks ago
See this thread183-1554659: SQL To Concatenate fields as to how to do the second part

markros replied 1 month, 4 weeks ago
Here is fnSplit function I use CODE -- Test query ALTER FUNCTION [dbo].[fnSplit] (@list VARCHAR(8000), @delim CHAR(1) = ',' ) RETURNS TABLE AS RETURN WITH csvtbl(START, stop) AS ( SELECT START = 1, stop = CHARINDEX(@delim COLLATE Slovenian_BIN2, @list + @delim) UNION ALL SELECT START = stop + 1, stop = CHARINDEX(@delim COLLATE Slovenian_BIN2,...

JeffModen replied 1 month, 3 weeks ago
mankish, What version of SQL Server are you using? It'll make a difference in the code for the answer on this. --Jeff Moden -------------------------------------------------- ----------------------------- " RBAR " is pronounced "ree-bar" and is a "Modenism" for " R ow B y A gonizing R ow"

markros replied 1 month, 3 weeks ago
See also http://br adsruminat ions.blogs pot.com/20 09/10/un-m aking-list -or-shredd ing-of-evi dence.html and try to apply it for your case.

SQLSister replied 1 month, 3 weeks ago
What you really need to do is change your exceedingly poor design. You should NEVER store mulitple peices if information in one field like that. You need a related table where you can store the data properly and then it is trivial to query. "NOTHING is more important in a database than integrity." ESquared

 

Top contributing authors

Name
Posts
markros
4
user's latest post:
Parse String
Published (2009-11-10 09:33:00)
See also http://br adsruminat ions.blogs pot.com/20 09/10/un-m aking-list -or-shredd ing-of-evi dence.html and try to apply it for your case.
mankish
1
user's latest post:
Parse String
Published (2009-11-06 15:52:00)
I have a table with a column called members and in it the rows are like ID Members ---------- ----------- 1 1\2\3 2 2\3\4 3 2\3 4 1\5 I have a reference table where 1 = father, 2= mother, 3=sister, 4=brother, 5=grapnparents. Is there any way I can query the memebers table like this ID Members ---------- ------------------ 1 father,mother,sister 2 mother,sister, brother 3 mother,sister 4 father,grandparents. What I want to do is just replace...
chapuchi30
1
user's latest post:
Parse String
Published (2009-11-06 16:33:00)
use the inner join sentence, something like select a.id,b.members from table1 a inner join table2 b on a.members=b.id
JeffModen
1
user's latest post:
Parse String
Published (2009-11-10 03:00:00)
mankish, What version of SQL Server are you using?  It'll make a difference in the code for the answer on this. --Jeff Moden ------------------------------------------------------------------------------- " RBAR " is pronounced "ree-bar" and is a "Modenism" for " R ow B y A gonizing R ow"
SQLSister
1
user's latest post:
Parse String
Published (2009-11-10 14:53:00)
What you really need to do is change your exceedingly poor design. You should NEVER store mulitple peices if information in one field like that. You need a related table where you can store the data properly and then it is trivial to query.   "NOTHING is more important in a database than integrity." ESquared  

Related threads on "Tek-Tips Forums":

Related threads on other sites:

Thread profile page for "Parse String" on http://www.tek-tips.com. This report page is a snippet summary view from a single thread "Parse String", located on the Message Board at http://www.tek-tips.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity