[dba-SQLServer] Review

Djabarov, Robert Robert.Djabarov at usaa.com
Mon May 3 16:05:27 CDT 2004


You're missing a closed parenthesis after:
 SET @LocationName = 'Office ' + CAST(@i AS VARCHAR(3)

Robert Djabarov
SQL Server & UDB
Sr. SQL Server Administrator
Phone: (210)  913-3148
Pager: (210) 753-3148
9800 Fredericksburg Rd. San Antonio, TX  78288
www.usaa.com

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of
Francisco H Tapia
Sent: Monday, May 03, 2004 3:48 PM
To: dba-sqlserver at databaseadvisors.com
Subject: [dba-SQLServer] Review

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


_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com




More information about the dba-SQLServer mailing list