Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS SQL -- RegEx (or something)

Posted on 2012-03-16
10
Medium Priority
?
521 Views
Last Modified: 2012-03-20
Change "select ExtensionSettings from Subscriptions"
so it only extracts "test3@test.com;test2@test.com"
on my 500+ results instead of getting the below ?

<ParameterValues><ParameterValue><Name>TO</Name><Value>test3@test.com;test2@test.com</Value></ParameterValue>
<ParameterValue><Name>ReplyTo</Name><Value>test@test.com</Value></ParameterValue>
<ParameterValue><Name>IncludeReport</Name><Value>True</Value></ParameterValue>
<ParameterValue><Name>RenderFormat</Name><Value>EXCEL</Value></ParameterValue>
<ParameterValue><Name>Subject</Name><Value>EOM -- @ReportName</Value>
0
Comment
Question by:finance_teacher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 31

Expert Comment

by:James Murrell
ID: 37729142
select ExtensionSettings from Subscriptions where ExtensionSettings = 'test3@test.com;test2@test.com'
0
 

Author Comment

by:finance_teacher
ID: 37729267
That get the entire ExtensionSettings column, I only want the a piece of it.

Like a SUBSTRING, but based on a REGEX (or something else).
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37731669
Why not use Xml Data Type Methods for this?  That would be far more precise than using something like PATINDEX()
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:finance_teacher
ID: 37733568
I read http://learnsqlserver.in/6/Xml-Data-Type-Methods.aspx, but have issues.

Please post an example solution.

Thanks
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37733787
Here you go:
DECLARE @MyXml xml =
'<ParameterValues>
	<ParameterValue>
		<Name>TO</Name>
		<Value>test3@test.com;test2@test.com</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>ReplyTo</Name>
		<Value>test@test.com</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>IncludeReport</Name>
		<Value>True</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>RenderFormat</Name>
		<Value>EXCEL</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>Subject</Name>
		<Value>EOM -- @ReportName</Value>
	</ParameterValue>
</ParameterValues>'

SELECT	t.c.value('Value[1]', 'varchar(50)')
FROM	@MyXml.nodes('ParameterValues/ParameterValue') T(C)

Open in new window

0
 

Author Comment

by:finance_teacher
ID: 37733955
My database table, subscriptions, has 500+ rows, how can I get your "DECLARE @MyXml xml..." to do something like "DECLARE @MyXml xml...select ExtensionSettings from Subscriptions..." ?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37736105
Like this:
SELECT  s.*,
        t.c.value('Value[1]', 'varchar(50)') ExtensionSettings
FROM    subscriptions s
        CROSS APPLY s.MyXml.nodes('ParameterValues/ParameterValue') T (C)

Open in new window

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 1600 total points
ID: 37736122
This is how I tested it:

DECLARE @subscriptions TABLE (MyXml xml)
INSERT @subscriptions (MyXml) VALUES (
'<ParameterValues>
	<ParameterValue>
		<Name>TO</Name>
		<Value>test3@test.com;test2@test.com</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>ReplyTo</Name>
		<Value>test@test.com</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>IncludeReport</Name>
		<Value>True</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>RenderFormat</Name>
		<Value>EXCEL</Value>
	</ParameterValue>
	<ParameterValue>
		<Name>Subject</Name>
		<Value>EOM -- @ReportName</Value>
	</ParameterValue>
</ParameterValues>')

SELECT  s.*,
        t.c.value('Value[1]', 'varchar(50)') ExtensionSettings
FROM    @subscriptions s
        CROSS APPLY s.MyXml.nodes('ParameterValues/ParameterValue') T (C)

Open in new window

0
 
LVL 12

Assisted Solution

by:kselvia
kselvia earned 400 total points
ID: 37739584
Credit to ACPerkins, but here is some code that should work with your SQL Report Server subscriptions table;

SELECT  Description, t.c.value('Value[1]', 'varchar(50)') ExtensionSettings        
FROM    
( select CAST(extensionsettings AS XML) ExtensionSettings, Description from subscriptions ) s
CROSS APPLY s.ExtensionSettings.nodes('/ParameterValues/ParameterValue') T (C)
WHERE t.c.value('Name[1]', 'varchar(50)') = 'TO'

Open in new window

0
 

Author Comment

by:finance_teacher
ID: 37741846
Ok, I changed the below from "varchar(50)" to "varchar(500)" and it works.

SELECT  t.c.value('Value[1]', 'varchar(500)') ExtensionSettings        
FROM    
( select CAST(extensionsettings AS XML) ExtensionSettings, Description from subscriptions ) s
CROSS APPLY s.ExtensionSettings.nodes('/ParameterValues/ParameterValue') T (C)
WHERE t.c.value('Name[1]', 'varchar(500)') = 'TO'
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question