Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1476 > unrolled thread

Extracting nth word in a string

Started bycontracer <contracer11@gmail.com>
First post2013-05-11 06:21 -0700
Last post2013-05-11 17:27 +0200
Articles 3 — 3 participants

Back to article view | Back to comp.databases.ms-sqlserver


Contents

  Extracting nth word in a string contracer <contracer11@gmail.com> - 2013-05-11 06:21 -0700
    Re: Extracting nth word in a string rja.carnegie@gmail.com - 2013-05-11 07:07 -0700
    Re: Extracting nth word in a string Erland Sommarskog <esquel@sommarskog.se> - 2013-05-11 17:27 +0200

#1476 — Extracting nth word in a string

Fromcontracer <contracer11@gmail.com>
Date2013-05-11 06:21 -0700
SubjectExtracting nth word in a string
Message-ID<0357973f-1b2f-4de6-bc76-3d2edd3b5411@googlegroups.com>
Hi,
Please, can you help me how extract nth word in string ccs.errormessage ?


Select n.caption, ccs.errormessage FROM APM_CurrentComponentStatus ccs WITH (NOLOCK)
INNER JOIN APM_Application a WITH (NOLOCK) ON ccs.ApplicationID = a.ID
INNER JOIN Nodes n WITH (NOLOCK) ON a.NodeID = n.NodeID
where ccs.ErrorMessage LIKE '%hit%'
order by 2 asc
 
 
 

ORACLE01 FS /apl/orawpsp hit 90% usage -> 533 MB available
         FS /bd1/orawppdata/sys hit 90% usage -> 199 MB available

[toc] | [next] | [standalone]


#1477

Fromrja.carnegie@gmail.com
Date2013-05-11 07:07 -0700
Message-ID<c516f57b-f52e-4272-8ccf-1d4bab10908e@googlegroups.com>
In reply to#1476
On Saturday, 11 May 2013 14:21:35 UTC+1, contracer  wrote:
> Hi,
> 
> Please, can you help me how extract nth word in string ccs.errormessage ?

I think /that's/ a case to write a user-defined function,
particularly if n isn't fixed.  In the function, you can
use CHARINDEX(' ', @message, @previousSpace+1) to find 
each word break - if the word break is a single space.

[toc] | [prev] | [next] | [standalone]


#1478

FromErland Sommarskog <esquel@sommarskog.se>
Date2013-05-11 17:27 +0200
Message-ID<XnsA1BDB1920994Yazorman@127.0.0.1>
In reply to#1476
contracer (contracer11@gmail.com) writes:
> Please, can you help me how extract nth word in string ccs.errormessage ?
> 
> 
> Select n.caption, ccs.errormessage FROM APM_CurrentComponentStatus ccs 
> WITH (NOLOCK)
> INNER JOIN APM_Application a WITH (NOLOCK) ON ccs.ApplicationID = a.ID
> INNER JOIN Nodes n WITH (NOLOCK) ON a.NodeID = n.NodeID
> where ccs.ErrorMessage LIKE '%hit%'
> order by 2 asc
>  
> 
> ORACLE01 FS /apl/orawpsp hit 90% usage -> 533 MB available
>          FS /bd1/orawppdata/sys hit 90% usage -> 199 MB available


One possibility is to use a string-to-table that numbers the
elements, and then filter on row number. 
 
 (SELECT str FROM string_to_table(ccc.errormessage) WHERE row_number = @n)

I have a number of such functions in this article on my web site: 
http://www.sommarskog.se/arrays-in-sql-2005.html


-- 
Erland Sommarskog, Stockholm, esquel@sommarskog.se

[toc] | [prev] | [standalone]


Back to top | Article view | comp.databases.ms-sqlserver


csiph-web