Traversing through Temp Table

  • Hi,

    I have i temp table as

    CREATE TABLE #TEMP (ID INT)

    In this temp table i would be having 2 or more than 2 records. They would be necessarily 0 or 1 value.

    Suppose if any one of the present value in temp table is 1 then i have to set a variable(Say the variable is @var) to 1. If all the records in the temp table are 0 then i have to set a variable(@var) value as 0.

  • If they can only ever be 0 or 1 then max will do the job, as if anything is set to 1 it will return 1 or if everything is 0 it will return 0

    SELECT @Var = MAX(ID) FROM #Temp

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

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