Multiple Input Parameters

  • Thread starter Thread starter Charles
  • Start date Start date
C

Charles

I am trying to selct o Stored Procedure based on an input
parameter and a specified one (Cancelled = True). Below
is the sysntax after the select query. They work
independant of each other but not together as displayed
below:

IF @UserID Is NOT NULL
BEGIN
SELECT @SQLString = 'WHERE UserID = ''' + @UserID + ''''
SELECT @SQLString = @SQLString + ' an Cancelled = True'

SELECT @SelectList = @SelectList + ' ' + @SQLString
END

Help... What to do?

--Execute the SQL statement.
EXECUTE(@SELECTLIST)
 
May be your @SQLString parameter is declared too short to contain the concatenation of two strings. May be you miss a space when you concatenate the two strings.

You should use the debugger in SQL Query Analyzer to check your complete sql statement. If you add a statement "print @SQLstring" in your code the complete contents of @SQLstring will be printed in the bottom window of the debugger. You can then copy this printed statement into a view in Enterprise manager to test it, or you can run it directly from SQL Query Analyzer. You will get an immediate response telling you if your statement works or not.

You start the debugger in SQL Query analyzer by right-clicking the stored procedure and then select "debug".

Regards

Tore

----- Charles wrote: -----

I am trying to selct o Stored Procedure based on an input
parameter and a specified one (Cancelled = True). Below
is the sysntax after the select query. They work
independant of each other but not together as displayed
below:

IF @UserID Is NOT NULL
BEGIN
SELECT @SQLString = 'WHERE UserID = ''' + @UserID + ''''
SELECT @SQLString = @SQLString + ' an Cancelled = True'

SELECT @SelectList = @SelectList + ' ' + @SQLString
END

Help... What to do?

--Execute the SQL statement.
EXECUTE(@SELECTLIST)
 
Back
Top