Results 1 to 3 of 3

Thread: SQL Server 2000 Cursor Problem

Threaded View

  1. #1

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    SQL Server 2000 Cursor Problem

    hello guys, i know this not the right forum but i thought there are quite a good number of SQL Server 2000 gurus as well, to help me out. i have the following piece of Code in T-SQL.
    Code:
    DECLARE @strIMEIColl VarChar(8000)
    DECLARE @strIMEI VarChar(15)
    
    DECLARE curMatched CURSOR
    FOR 
    SELECT DISTINCT(IMEI) FROM IC_Data
    OPEN curMatched
    
    FETCH NEXT FROM curMatched INTO @strIMEI
    SELECT @strIMEIColl =  CHAR(39) + @strIMEI + Char(39)
    
    FETCH NEXT FROM curMatched INTO @strIMEI
    	WHILE @@FETCH_STATUS = 0 
    	BEGIN
    		select @strIMEIColl = @strIMEIColl + ',' + CHAR(39) + @strIMEI + Char(39)			
    		FETCH NEXT FROM curMatched INTO	@strIMEI
    	END
    
    WHILE @strIMEI = '' BEGIN
    	SELECT @strIMEIColl = @strIMEIColl + ',' + @strIMEI	
    	FETCH NEXT FROM curMatched INTO @strIMEI
    END
    
    CLOSE curMatched
    DEALLOCATE curMatched
    PRINT @strIMEIColl
    SELECT * FROM IC_Data WHERE IMEI IN(@strIMEIColl)
    The variable @strIMEIColl has more than 20 Comma Seperated list of IMEI numbers, but still the Select statement wont show any thing. The PRINT @strIMEIColl statement shows the values correctly.
    I tried using
    Please tell me where am i getting wrong, or is there an alternative to it also ?!?!
    Last edited by Hack; Aug 24th, 2006 at 06:37 AM. Reason: Added [code] [/code] tags for more clarity.
    Women ...r like tea bags, you neva know how strong they really r untill u put them in hot water

    Huzefa Yousuf
    Software Engineer
    Verticity Inc.
    +92-345-2235303

    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width