SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Pass a string into SP and parse on space


Pass a string into SP and parse on space

Author
Message
Evil Kraig F
Evil Kraig F
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8763 Visits: 7660
j2cagle (5/9/2013)
Yes that helps...but I'm trying to resolve this without touching the VB code.


then we need to see the target proc and a sample call.


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Sioban Krzywicki
Sioban Krzywicki
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1891 Visits: 8090
j2cagle (5/9/2013)
Yes that helps...but I'm trying to resolve this without touching the VB code.


Have you tried passing it in with the single or double quotes? I think the single quotes should resolve the issue.
You say you don't want to change the VB code, so how is the variable entered? Through a text box in the interface? From a file? From another database or query?
What version of VB is this? (The answer doesn't matter much here, I'm just curious)

--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
Brandie Tarvin
Brandie Tarvin
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15100 Visits: 9006
j2cagle (5/9/2013)
Yes that helps...but I'm trying to resolve this without touching the VB code.


I don't think you have a choice in the matter. The problem probably isn't within the SQL but within the VB code. It would help us to help you if you posted both the VB code and the SQL code so we could verify.

Are you using the DTS.Variable.ToString to pass the string from the VB code to the SQL?

Bevan's suggestion is the best (exactly what I would do). I.E., using CHARINDEX() and then LEFT() in the T-SQL code, but if that's not working for you, then your issue is in the VB code, not in the T-SQL.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28966 Visits: 39984
in both vb6 or VB.Net, you can split the string into elements, and take the first element, or you can use the built in string functions.

'VB.Net: both return "ABC"

Dim SomeString As String = "ABC DEF GHI"
Dim val = SomeString.Substring(0, SomeString.IndexOf(" "))

Dim arr() As String = "ABC DEF GHI".Split(" ")
val = arr(0)




'VB6
Dim SomeString As String
SomeString = "ABC DEF GHI"
Dim val As String
val = Left(SomeString, InStr(SomeString, " ") - 1) '-1 to remove the space
Dim arr() As String
arr = Split("ABC DEF GHI", " ")
val = arr(0)



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

venoym
venoym
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1467 Visits: 2082
Brandie Tarvin (5/10/2013)
j2cagle (5/9/2013)
Yes that helps...but I'm trying to resolve this without touching the VB code.


I don't think you have a choice in the matter. The problem probably isn't within the SQL but within the VB code. It would help us to help you if you posted both the VB code and the SQL code so we could verify.

Are you using the DTS.Variable.ToString to pass the string from the VB code to the SQL?

Bevan's suggestion is the best (exactly what I would do). I.E., using CHARINDEX() and then LEFT() in the T-SQL code, but if that's not working for you, then your issue is in the VB code, not in the T-SQL.


I think the likely scenario is that the vb code is doing something like this:

ocmd = ADODB.Command
ocmd.CommandText = "EXEC dbo.[Procedure] " + sVariable
ocmd.Execute()

If you notice, that is building dynamic sql (very common in the VB6 world). With Numerics this is fine and not an issue. With strings it's a huge problem. So, really, until we get the actual VB code, we can't determine the cause.
j2cagle
j2cagle
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 22
Yes, Say Hey Kid, it's very similar to what you posted. I agree with a previous post...the real issue is in the VB code. However, I wanted to determine if I could handle this situation within the SQL code. The VB code is potentially lost and not re-buildable, unfortunately.
Brandie Tarvin
Brandie Tarvin
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15100 Visits: 9006
j2cagle (5/10/2013)
Yes, Say Hey Kid, it's very similar to what you posted. I agree with a previous post...the real issue is in the VB code. However, I wanted to determine if I could handle this situation within the SQL code. The VB code is potentially lost and not re-buildable, unfortunately.


Until you can get the VB code to push the correct value to SQL Server, there's nothing T-SQL can do to rectify the problem.

When you say "lost," what exactly do you mean? I assume there's a working version of it somewhere or you wouldn't be getting anything at all from it.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
j2cagle
j2cagle
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 22
By "lost" I mean...the code is out there running, and we have versions of the source code in multiple locations. These multiple locations don't appear to be the version that is out there running. So, I was attempting to catch and correct the issue in the called SQL.

Just to reiterate...

I'm just looking for a way, that when passed "ABC DEF GHI", I could handle it in SQL to simply look only at the value up to the first space.

If that can't be done, that's fine...I was just doing some investigation...
Brandie Tarvin
Brandie Tarvin
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15100 Visits: 9006
I'm sorry, but we really can't answer that question for you. If you post the stored procedure we can look at it to see if there's anything specific to the proc that's causing your error message. Other than that, we are out of suggestions.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Steve Thompson
Steve Thompson
SSC-Addicted
SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)

Group: General Forum Members
Points: 423 Visits: 2102
venoym (5/10/2013)
I think the likely scenario is that the vb code is doing something like this:

ocmd = ADODB.Command
ocmd.CommandText = "EXEC dbo.[Procedure] " + sVariable
ocmd.Execute()



If you're passing the parameter value into the CommandText in-line, you should try wrapping it in single quotes like this:

ocmd.CommandText = "EXEC dbo.[Procedure] " + "'" + sVariable + "'"

This isn't a best practice - it makes your data layer susceptible to SQL Injection attacks. You'd do better passing the value in through a strongly typed parameter. But this should fix the immediate problem.

Unfortunately, I'm not sure you can fix this without making some change to the VB code - without the single quotes the SP will consume ABC as the parameter value and throw the exception when it gets to the characters after the space (which sounds like exactly what you're seeing).
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search