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: (3203)
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:


System Message:
  • Your ASP & ASP.NET script has been sent. Please allow 48 hours for processing.


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 ]