Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Traversing through Temp Table Expand / Collapse
Author
Message
Posted Thursday, November 15, 2012 3:36 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, April 07, 2014 11:09 PM
Points: 220, Visits: 536
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.
Post #1385047
Posted Thursday, November 15, 2012 3:41 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
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





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1385050
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse