[dba-SQLServer] Review

Francisco H Tapia my.lists at verizon.net
Mon May 3 15:48:23 CDT 2004


I need to get a 2nd pair of eyes on this...  The purpose of this script 
is to go into tbl_address and prevent a duplication of the name "main 
office" for companyID selected.  So far It appears to me as if it's fine 
but I keep getting an error on the Keyword WHILE, what did I miss... 
i've been staring at it for 30min :(

Declare @CompanyID as UniqueIdentifier, @LocationName As Varchar(100)
SET @CompanyID = 'E0979997-E5F1-4DC0-8597-5EB649DEC872'
IF IsNull(@LocationName,'') = ''
   BEGIN
     IF EXISTS(Select LocationName from tbl_Address WHERE CompanyID = 
@CompanyID AND LocationName = 'Main Office')
    BEGIN
       DECLARE @i AS INT
         SET @i = 1
       SET @LocationName = 'Office ' + CAST(@i AS VARCHAR(3)
          WHILE EXISTS(Select LocationName from tbl_Address WHERE 
CompanyID = @CompanyID AND LocationName = @LocationName)
             BEGIN
            SET @LocationName = 'Office ' + CAST(@i AS VARCHAR(3)
                SET @i = @i + 1
             END
     
    END
     ELSE
    BEGIN
       SET @LocationName = 'Main Office'
    END
   END

-- 
-Francisco





More information about the dba-SQLServer mailing list