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. Database & SysAdmin
  3. Database
  4. Cursor_sql server 2005

Cursor_sql server 2005

Scheduled Pinned Locked Moved Database
sysadminlearning
5 Posts 3 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.
  • R Offline
    R Offline
    r a j u u
    wrote on last edited by
    #1

    hi, I am learning stage of cursor.here date format is displaying like 2007-06-22 01:54:02.000. I am Struggling for getting normal date format like 11/12/2005...Plz See the following Code and reply me ALTER procedure [dbo].[WCReport] as begin create table #temp21 ( Ason datetime ,SubScriberEmail varchar(50),SvcActivationDate datetime, PkgActivationDate datetime,RenewalDate datetime ) DECLARE @cursorVar CURSOR SET @cursorVar = CURSOR Forward_Only FOR SELECT regdate,email,wct.dt from wc_transaction as wct,wc_user as wcu WHERE wct.PID=wcu.ID --open the cursor OPEN @cursorVar DECLARE @regdate datetime, @email varchar(50),@dt datetime --fetches the current row, which is the first FETCH FROM @cursorVar INTO @regdate,@email,@dt WHILE @@fetch_status = 0 BEGIN insert into #TEMP21(Ason,SubscriberEmail,SvcActivationDate,PkgActivationDate,RenewalDate) VALUES(@regdate,@email,@regdate,@regdate,@dt) FETCH Next FROM @cursorVar INTO @regdate,@email,@dt END begin select * from #temp21 return end CLOSE @cursorVar DEALLOCATE @cursorVar end exec WCReport

    Rajendran

    N 1 Reply Last reply
    0
    • R r a j u u

      hi, I am learning stage of cursor.here date format is displaying like 2007-06-22 01:54:02.000. I am Struggling for getting normal date format like 11/12/2005...Plz See the following Code and reply me ALTER procedure [dbo].[WCReport] as begin create table #temp21 ( Ason datetime ,SubScriberEmail varchar(50),SvcActivationDate datetime, PkgActivationDate datetime,RenewalDate datetime ) DECLARE @cursorVar CURSOR SET @cursorVar = CURSOR Forward_Only FOR SELECT regdate,email,wct.dt from wc_transaction as wct,wc_user as wcu WHERE wct.PID=wcu.ID --open the cursor OPEN @cursorVar DECLARE @regdate datetime, @email varchar(50),@dt datetime --fetches the current row, which is the first FETCH FROM @cursorVar INTO @regdate,@email,@dt WHILE @@fetch_status = 0 BEGIN insert into #TEMP21(Ason,SubscriberEmail,SvcActivationDate,PkgActivationDate,RenewalDate) VALUES(@regdate,@email,@regdate,@regdate,@dt) FETCH Next FROM @cursorVar INTO @regdate,@email,@dt END begin select * from #temp21 return end CLOSE @cursorVar DEALLOCATE @cursorVar end exec WCReport

      Rajendran

      N Offline
      N Offline
      neeraj_indianic
      wrote on last edited by
      #2

      Instead of using select * from #temp21 specify the each column name and in the date column use convert function. now your select query will be like this. select convert(varchar,Ason,101),SubScriberEmailfrom, convert(varchar,SvcActivationDate,101),convert(varchar,PkgActivationDate,101), convert(varchar,RenewalDate,101) from #temp21

      R 1 Reply Last reply
      0
      • N neeraj_indianic

        Instead of using select * from #temp21 specify the each column name and in the date column use convert function. now your select query will be like this. select convert(varchar,Ason,101),SubScriberEmailfrom, convert(varchar,SvcActivationDate,101),convert(varchar,PkgActivationDate,101), convert(varchar,RenewalDate,101) from #temp21

        R Offline
        R Offline
        r a j u u
        wrote on last edited by
        #3

        Hi, I have used your query Its working fine....Thanks alot. I have another doubt....actually I am generating reports using this cursor.here I have to give dublicate column name like Status(if condition is true)..So I want to know how to provide an alias name for that Status(Status is not their in Database)....If u know plz reply me... thanks

        Rajendran

        N 1 Reply Last reply
        0
        • R r a j u u

          Hi, I have used your query Its working fine....Thanks alot. I have another doubt....actually I am generating reports using this cursor.here I have to give dublicate column name like Status(if condition is true)..So I want to know how to provide an alias name for that Status(Status is not their in Database)....If u know plz reply me... thanks

          Rajendran

          N Offline
          N Offline
          Navdeep Bhardwaj
          wrote on last edited by
          #4

          Hi Try something like SELECT CASE WHEN Dt < '2006-12-31' THEN 'Archived' WHEN Dt < '2007-06-30' THEN 'OLD' ELSE 'New' END AS [Status] FROM MyTable

          Nav

          R 1 Reply Last reply
          0
          • N Navdeep Bhardwaj

            Hi Try something like SELECT CASE WHEN Dt < '2006-12-31' THEN 'Archived' WHEN Dt < '2007-06-30' THEN 'OLD' ELSE 'New' END AS [Status] FROM MyTable

            Nav

            R Offline
            R Offline
            r a j u u
            wrote on last edited by
            #5

            Thanks alot....its working ..

            Rajendran

            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