Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Script Quote Issue

$
0
0

Hi Guys,

Below you will see my script that I'm trying to put together which enumerates through a stored variable(3 letter strings) and incorporates them into an update script; however, I am having a problem with my quotes and I'm not sure how to structure my update statement within the context of my script. Any ideas? For simplicity purposes, I just put the quoting scheme back to the basic single quotes before start and end of finish.  Error message: Must declare the scalar variable "@currencyCode".



DECLARE @currencyCode VARCHAR(255)
DECLARE @cmd VARCHAR(255)



DECLARE tableCursor CURSOR

FOR

SELECT CRRNCY_CD FROM CSM_CURRENCY

OPEN tableCursor

    FETCH NEXT FROM tableCursor INTO @currencyCode
    WHILE @@FETCH_STATUS = 0

    BEGIN

        SET @cmd= 'UPDATE CSM_CURRENCY SET CRRNCY_SEC_ID = (SELECT SEC_ID FROM CSM_SECURITY
                   WHERE LOC_CRRNCY_CD=@currencyCode
                   AND SEC_ID LIKE [0-9][0-9][0-9])WHERE CRRNCY_CD=@currencyCode'
        EXEC(@cmd)
        --PRINT @crrncycd
        FETCH NEXT FROM tableCursor INTO @currencyCode
 
    END
    
CLOSE tableCursor
DEALLOCATE tableCursor

Thanks!




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>