?
Solved

Change String

Posted on 2013-05-10
3
Medium Priority
?
428 Views
Last Modified: 2013-05-10
I have a field in a SQL table that I need to update based on ID

The SQL is

Update myTable
set  ExecSQL =  @newSQL
where id = @id

An example of the string I'm passing in from my Web VB code is
usp_EmailsForSpecialtyStates 'MA','ER' True, 1000, 365, False, 1, Special, 1, 0

And all I need to do is change that first TRue to a false so that the new value would be
usp_EmailsForSpecialtyStates 'MA','ER' False, 1000, 365, False, 1, Special, 1, 0

Some caveates are that the first two sections are single quotes so that has to be handled
Also...
The string could come in as
usp_EmailsForSpecialtyStates 'CA,CT,KY,MA','ER' True, 1000, 365, False, 1, Special, 1, 0

It's the first filed after the first two sections (States and Stecialty)

And if that first True is already a false...ignore the update.
0
Comment
Question by:lrbrister
[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
  • 2
3 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 39156900
Hi,

So the fileid in your examples is 1000, no?

Regards
  David

PS Suggest that the multiple states thing is a bit of a pest! It means that the string needs to be properly parsed, and not just count the commas!
0
 
LVL 35

Accepted Solution

by:
David Todd earned 2000 total points
ID: 39156973
Hi,

Here is first draft code to parse your string. As you asked in SQL topics, this is in SQL.

use tempdb
go

declare @s varchar( max )
set @s = 'usp_EmailsForSpecialtyStates, ''MA'',''ER'', True, 1000, 365, False, 1, Special, 1, 0'

declare @c int
declare @pc int

-- test parse string into components
while 1 = 1 begin
	set @c = charindex( ',', @s, isnull( @pc, 0 ))

	if @c = 0
		break

	declare @p varchar( max )
	set @p = substring( @s, isnull( @pc, 0 ), @c - isnull( @pc, 0 ))

	if left( @p, 1 ) = ' ' 
		set @p = right( @p, len( @p ) - 1 )

	print @p

	set @pc = @c + 1

end

Open in new window

Note that I've added two commas to your string.

Regards
  David
0
 

Author Closing Comment

by:lrbrister
ID: 39157031
That's it. Thanks
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

770 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