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. Stored Procedures SQL Server

Stored Procedures SQL Server

Scheduled Pinned Locked Moved Database
databasequestionsql-serversysadmin
8 Posts 6 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.
  • D Offline
    D Offline
    damokk
    wrote on last edited by
    #1

    I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks

    S C M A A 5 Replies Last reply
    0
    • D damokk

      I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks

      S Offline
      S Offline
      scottgp
      wrote on last edited by
      #2

      Do you mean like this - http://sqlserverplanet.com/tsql/insert-stored-procedure-results-into-table[^]? Scott

      1 Reply Last reply
      0
      • D damokk

        I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks

        C Offline
        C Offline
        Corporal Agarn
        wrote on last edited by
        #3

        Just use an insert:

        CREATE PROCEDURE spGetMemReminder
        AS
        INSERT INTO YourTableNameHere (FullName, ExpiryDate)
        SELECT users.fullname, membership.expiryDate from membership
        inner join users on membership.uid=users.uid
        where expiryDate = CAST(DATEADD(day, 7, getdate()) AS DATE

        if expiryDate is a date column it is better to do date compare than to convert both sides.

        D 1 Reply Last reply
        0
        • D damokk

          I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Use an insert statement, that is not why I am posting a reply. There are many ways to compare dates, comparing string (varchar) is probably the worst possible method. Do some research into the datetime object, you could have used datediff or dateadd neither of which require a convert. Never underestimate the power of human stupidity RAH

          D 1 Reply Last reply
          0
          • C Corporal Agarn

            Just use an insert:

            CREATE PROCEDURE spGetMemReminder
            AS
            INSERT INTO YourTableNameHere (FullName, ExpiryDate)
            SELECT users.fullname, membership.expiryDate from membership
            inner join users on membership.uid=users.uid
            where expiryDate = CAST(DATEADD(day, 7, getdate()) AS DATE

            if expiryDate is a date column it is better to do date compare than to convert both sides.

            D Offline
            D Offline
            damokk
            wrote on last edited by
            #5

            thanks!

            1 Reply Last reply
            0
            • M Mycroft Holmes

              Use an insert statement, that is not why I am posting a reply. There are many ways to compare dates, comparing string (varchar) is probably the worst possible method. Do some research into the datetime object, you could have used datediff or dateadd neither of which require a convert. Never underestimate the power of human stupidity RAH

              D Offline
              D Offline
              damokk
              wrote on last edited by
              #6

              ok will do. thanks!

              1 Reply Last reply
              0
              • D damokk

                I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks

                A Offline
                A Offline
                Arun Vasu
                wrote on last edited by
                #7

                Hai.... You can do it by table varible. create proc

                spGetMemReminder
                as
                select users.fullname, membership.expiryDate from membership
                inner join users on membership.uid=users.uid
                where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105)
                end

                GO

                CREATE PROCEDURE InsertMember
                AS
                BEGIN
                SET NOCOUNT ON
                DECLARE @TABLE TABLE(fullname nvarchar(10), expiryDate datetime)

                    insert into @TABLE
                    exec spGetMemReminder
                
                    insert into yourothertable
                    select \* from @TABLE
                SET NOCOUNT OFF
                

                END

                1 Reply Last reply
                0
                • D damokk

                  I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks

                  A Offline
                  A Offline
                  Aatif Ali from Bangalore
                  wrote on last edited by
                  #8

                  I think 'Insert into' query will help you

                  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