Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. While Loop Problem in SQL

While Loop Problem in SQL

Scheduled Pinned Locked Moved ASP.NET
helpdatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jintalPatel
    wrote on last edited by
    #1

    DECLARE @spot SMALLINT DECLARE @str VARCHAR(8000) DECLARE @strQuery nVARCHAR(1000) DECLARE @sql VARCHAR(8000) DECLARE @cslist VARCHAR(8000) declare @Count int set @Count=0 set @cslist='CallLog1230,CallLog2230' MainLoop: WHILE @cslist <> '' BEGIN SET @spot = CHARINDEX(',', @cslist) print @spot IF @spot>0 BEGIN SET @str = CAST(LEFT(@cslist, @spot-1) AS varchar) SET @cslist = RIGHT(@cslist, LEN(@cslist)-@spot) print @cslist goto InComing goto OutGoing END ELSE BEGIN SET @str = CAST(@cslist AS varchar) SET @cslist = '' print @str if(@Count=0) Begin set @Count=1 goto InComing goto OutGoing End Else goto EndLoop END End InComing: Begin print 'IN' print @str End OutGoing: Begin print 'OUT' print @str goto MainLoop End EndLoop: return I am not return from the While loop Please help me to find where i am wrong

    P 1 Reply Last reply
    0
    • J jintalPatel

      DECLARE @spot SMALLINT DECLARE @str VARCHAR(8000) DECLARE @strQuery nVARCHAR(1000) DECLARE @sql VARCHAR(8000) DECLARE @cslist VARCHAR(8000) declare @Count int set @Count=0 set @cslist='CallLog1230,CallLog2230' MainLoop: WHILE @cslist <> '' BEGIN SET @spot = CHARINDEX(',', @cslist) print @spot IF @spot>0 BEGIN SET @str = CAST(LEFT(@cslist, @spot-1) AS varchar) SET @cslist = RIGHT(@cslist, LEN(@cslist)-@spot) print @cslist goto InComing goto OutGoing END ELSE BEGIN SET @str = CAST(@cslist AS varchar) SET @cslist = '' print @str if(@Count=0) Begin set @Count=1 goto InComing goto OutGoing End Else goto EndLoop END End InComing: Begin print 'IN' print @str End OutGoing: Begin print 'OUT' print @str goto MainLoop End EndLoop: return I am not return from the While loop Please help me to find where i am wrong

      P Offline
      P Offline
      Panchal Hardik
      wrote on last edited by
      #2

      Remove "goto MainLoop" from bottom of "OutGoing:"

      Hardik Panchal

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups