Solved

Change String

Posted on 2013-05-10
3
425 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
  • 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to union three related tables in one flat file? 8 43
SQL, add where clause 5 23
sql server query 18 37
MS SQL Server select from Sub Table 14 23
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

856 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