Products
Services
Contact Us

Scripts: asp :: MS SQL and Database :: Library Article #18

Developer's Section

Convert an INT to String inside a Stored Procedure in MS SQL Server
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1752)
Favorites:

Learn a simple technique to convert any integer into a string inside a Stored Procedure in MS SQL Server.

You can call the function method sp_executesql to convert any integer parameter inside a stored procedure to its string equivalent.

Example:

 Code Snippet 1

CREATE PROCEDURE [dbo].[USP_getPassengersINFO] 
  @passengerID int, 
  @busID int

AS
BEGIN
  -- The idea is to create your sql statements strings with the
  -- representation of the integers as simple string variables prefixed with @.
  -- Then, on the actual call to retrieve the data we pass the integer variables.
  SET NOCOUNT ON;
  Declare @SQL NVarChar(3000);

  Select @SQL = 'SELECT DISTINCT passenger.*
               FROM passenger WHERE passenger.passID = @passengerID and
               passenger.busID = @busID';

  Exec sp_executesql @SQL, N'@passengerID int, @busID int ', @passengerID, @busID

END



See other Scripts in MS SQL and Database

Submit Your Scripts:

If you would like to have your ASP & ASP.NET scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]