How can i use parameters as aliases in the select statement within the stored procedure

  • How can i use parameters as aliases of columns headers in the select statement within the stored procedure like

    Create PROCEDURE spTest (@id nvarchar(50),@_Name nvarchar(50))

    AS

    Select EmpID as @ID ,EmpName as @Name from DataBase

    this way make an error "There is an error near @ID"

    SO if any one know how can i do that??????????????????????????:)

    YoU CaN't LoSe WhAt YoU NeVeR HaD;)

  • Create PROCEDURE spTest (@id nvarchar(50),@_Name nvarchar(50))

    AS

    Select EmpID as @ID ,EmpName as @Name from DataBase

    There is not enough information here to figure out what you are trying to do or why. Couple basic things wrong with what you are doing...

    Specify parameters as output if you are going to capture values back into them and use them in this manner.

    Select @ID=EmpID, @Name = EmpName from database where row = xxxx. The manner you are selecting will only work for you if you are returning 1 row of data so you need to get a specific where clause.

    If this does not help, please post a better example of what you are trying to do and why (-:

  • You might have to go the dynamic route on this one:

    Declare @SQL nvarchar(1000)

    Set @SQL = 'Select EmpID as ' + @ID + ' ,EmpName as ' + @Name + ' from DataBase'

    exec sp_executesql @SQL

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply