Value from Query

  • Compare both

    declare @test-2 varchar(10)

    declare @field varchar(10)

    SET @field = 'CustomerID'

    Select @test-2 = @field from Customers WHERE     (City = 'Berlin')

    Print @test-2

    this prints CustomerID (the field Name as such) Instead ALFKI.

    ---------------------------------

    SELECT     CustomerID FROM         Customers WHERE     (City = 'Berlin')

     

    here my result is ALFKI.

    I need the Same in the above.

     

    Help Me.

  • CREATE PROCEDURE MyProc

    @Field VARCHAR(50)

    AS

    DECLARE @StrQry VARCHAR(1000)

    SET @StrQry = 'SELECT ' + @Field + ' FROM Customers WHERE     (City = ''Berlin'')'

    EXEC (@StrQry)

    GO

    EXEC MyProc 'CustomerID'

    GO

    Prasad Bhogadi
    www.inforaise.com

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

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