locked
How to assign value to a parameter using select query? RRS feed

  • Question

  • Hi All,

     

    @Data = Select data from table where dataid=23


     

    Is it possible?

    I am getting error ..

     

    Help me how to use the select query in assigning to a parameter.

     

    Thank you

    Monday, June 7, 2010 10:21 AM

Answers

  • Hi,

    Try this:

    DECLARE @Data datatype
    SET @Data = (Select data from table1 where dataid=23)

    Make sure, you get only 1 item from your select statement.

    I hope it helps.

    J.


    There are 10 type of people. Those who understand binary and those who do not.
    Monday, June 7, 2010 10:33 AM

All replies

  • Hi,

    Try this:

    DECLARE @Data datatype
    SET @Data = (Select data from table1 where dataid=23)

    Make sure, you get only 1 item from your select statement.

    I hope it helps.

    J.


    There are 10 type of people. Those who understand binary and those who do not.
    Monday, June 7, 2010 10:33 AM
  • Select @data = data from table where dataid=23

     

    NM

    Monday, June 7, 2010 10:33 AM
  • CREATE TABLE Data
    (Sno INT IDENTITY(1,1),[Name] VARCHAR(150))
    INSERT INTO Data
    ([Name])
    VALUES('Ragu')
    DECLARE @Data VARCHAR(50)
    SET @Data=(SELECT [Name] FROM Data WHERE Sno=3)
    SELECT @Data

    -----OR-----------

    DECLARE @Data VARCHAR(50)
    SELECT @Data=[Name] FROM Data WHERE Sno=3
    SELECT @Data

     

     

    Thanks

    Ramesh.M

    Monday, June 7, 2010 10:42 AM