0

I have an sql stored procedure like this:

CREATE PROCEDURE [dbo].[usp_Test_ListProcessSQL]

@LocationIDs as varchar(max) =''

AS 

BEGIN

    IF EXISTS(SELECT  dbo.Locations.LocationID FROM dbo.Locations where  LocationID in (@LocationIDs))
        Return 0
    ELSE
        Return 1
END

when i run it like this:

usp_Test_ListProcessSQL 2478

it returns 0

but when i run it from VB 6 code, It returns 1

Public Function TestListProcessSQL(lLocationId As String) As Integer
Dim cmd As ADODB.Command, prm As ADODB.Parameter

    Set cmd = New ADODB.Command

    cmd.ActiveConnection = cn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "usp_Test_ListProcessSQL_True"


    With cmd
        .Parameters.Append .CreateParameter("return_value", adInteger, adParamReturnValue)
        .Parameters.Append .CreateParameter("@LocationIDs", adBSTR, adParamInput, , lLocationId)
    End With

    cmd.Execute
    TestListProcessSQL = cmd.Parameters("return_value")

End Function

Please suggest why code is returning wrong/different value

4
  • 2
    You're making a classic mistake (by the look of things) of assuming that a single string that contains commas is, in any way, going to be treated the same as multiple values separated by commas. There are plenty of questions on here about parameterizing IN, if you'd care to search for them. Commented Nov 11, 2013 at 7:41
  • @Damien_The_Unbeliever I am testing this sp with same input parameter but result is different from VB6 app vs SQL query window Commented Nov 11, 2013 at 7:52
  • 1
    You may be trying it with just one value (for now) but the fact that you've given your parameter a plural name, and you're using it in an IN clause indicate that you're going down the wrong route - you're going to have to restructure your stored procedure anyway to accommodate multiple values, there's not much point spending time fixing it for the one scenario where it may work. Commented Nov 11, 2013 at 7:54
  • I think maybe this might help you stackoverflow.com/questions/4471449/… Commented Nov 11, 2013 at 10:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.