Adding Parameter to existing Param with select

  • I want to add an existing value to a new value that was determined by a select statement. How can this be done?

     

    select @Value = Value1 from t_Table where active=1

    set @Value = @Value + (select Value2 from t_Table where active =1)

    This doesn't work but it's the basic idea of what I'm trying to accomplish.

  • Can you give me more information as how this "doesn't work"? 

    DECLARE @t_Table TABLE( Value1 varchar(10) NOT NULL, 

                                            Value2 integer NOT NULL, 

                                            Active bit NOT NULL)

    INSERT INTO @t_Table VALUES ('aaaa', 1, 0)

    INSERT INTO @t_Table VALUES ('xxxx', 2, 1)

    INSERT INTO @t_Table VALUES ('bbbb', 3, 0)

    INSERT INTO @t_Table VALUES ('yyyy', 4, 1)

    INSERT INTO @t_Table VALUES ('bbbb', 5, 0)

    INSERT INTO @t_Table VALUES ('zzzz', 6, 1)

    DECLARE @Value varchar(25)

    SELECT @Value = Value1 FROM @t_Table WHERE active = 1

    SELECT @Value

    SET @Value = @Value + CONVERT( varchar(2), (SELECT Value2 FROM @t_Table WHERE active = 1 AND Value1 = @Value))

    SELECT @Value

    I wasn't born stupid - I had to study.

  • Thanks Farrell, will work on it with that suggestion! Have a good one.

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

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