Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on 

Need help with not exists

Can someone take a look at my not exists statement. I think it is hanging when I run my sql stored procedure.
Look at my not exists statement : IF NOT EXISTS(SELECT FUAD_ITS_CLERK_ID = @lchFITS_PREFIX + RandomId())
It does not look right to me, so maybe I just don't understand how to do it properly.


OPEN CURS_EMP
@lchFITS_SUFFIX= CONVERT(INT, @lchSuffix)
FETCH NEXT FROM CURS_EMP
INTO @lchPSUS_USER_NUM, @lchFITS_STATE_CD, @lchFITS_PREFIX
SELECT lchFITS_SUFFIX = @lchFITS_SUFFIX+1

WHILE @@FETCH_STATUS = 0
BEGIN
        SET @ClerkIdIsUnique = 0
        WHILE(@ClerkIdIsUnique = 0)
        BEGIN
             IF NOT EXISTS(SELECT FUAD_ITS_CLERK_ID = @lchFITS_PREFIX + RandomId())
            BEGIN
                     UPDATE SMT_FCTS_FUAD_TOPL_USR SET
                        FUAD_ITS_CLERK_ID =  @lchFITS_PREFIX + RandomId()
                         WHERE PSUS_USER_NUM = @lchPSUS_USER_NUM
                         AND (FUAD_ITS_CLERK_ID = @lchPSUS_USER_NUM
                     
                         UPDATE SMT_FCTS_FITS_STATE_CDS
                         SET FITS_SUFFIX = CONVERT(VARCHAR, @lchFITS_SUFFIX)
                         FETCH NEXT FROM CURS_EMP
                    INTO @lchPSUS_USER_NUM, @lchFITS_STATE_CD, @lchFITS_PREFIX
                         SET @ClerkIdIsUnique = 1
                         SELECT @lchFITS_SUFFIX = @lchFITS_SUFFIX+1
               END
               ELSE SELECT @lchFITS_SUFFIX = @lchFITS_SUFFIX+1
          END
Microsoft SQL Server

Avatar of undefined
Last Comment
Vitor Montalvão
ASKER CERTIFIED SOLUTION
Avatar of Phillip Burton
Phillip Burton

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo