Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Pass a string into SP and parse on space Expand / Collapse
Author
Message
Posted Thursday, May 9, 2013 4:55 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 5,401, Visits: 7,513
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
Post #1451377
Posted Thursday, May 9, 2013 8:26 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 840, Visits: 7,374
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
Post #1451398
Posted Friday, May 10, 2013 4:12 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:28 AM
Points: 5,584, Visits: 6,380
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1451505
Posted Friday, May 10, 2013 7:13 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:54 AM
Points: 12,905, Visits: 32,163
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1451573
Posted Friday, May 10, 2013 7:26 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:01 AM
Points: 1,029, Visits: 1,751
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.
Post #1451581
Posted Friday, May 10, 2013 7:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, January 7, 2014 11:14 AM
Points: 19, 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.
Post #1451585
Posted Friday, May 10, 2013 7:34 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:28 AM
Points: 5,584, Visits: 6,380
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1451589
Posted Friday, May 10, 2013 8:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, January 7, 2014 11:14 AM
Points: 19, 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...
Post #1451608
Posted Friday, May 10, 2013 8:10 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:28 AM
Points: 5,584, Visits: 6,380
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1451613
Posted Friday, May 10, 2013 8:13 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, October 20, 2014 8:21 AM
Points: 266, Visits: 1,692
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).
Post #1451615
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse