Results 1 to 3 of 3

 

Thread: SQL Stored Procedure - can anyone help plse

  1. #1
    Big Member

    Status
    Offline
    Join Date
    Jan 2004
    Location
    Surrey
    Posts
    273
    Thanks
    50
    Thanked 23 Times in 14 Posts


    I'm trying to get a stored procedure to work that will copy over the clickthrough and display details from my main database to a new table named based on (at the monent) the month& & year. I can get the name I need for the table however have lucked out in getting it to create the table simply getting an error when using the variable @MonthYr as the table name.

    I've shown my code below, any offers on what the issue is?

    Declare @MonthYr varchar(14)
    Declare @StatsMonth datetime
    Declare @StatsYear varchar(8)

    Set @StatsMonth=month(GetDate())
    Set @StatsYear=CAST((year(getdate()) % 100) AS CHAR(4))
    Set @MonthYr='Stats_'+Cast(@StatsMonth as Varchar(3))+Cast(@StatsYear as varchar(4))


    SELECT Prod_ID, Product_Name, Displayed_Count, Clickedcount, validtodate, validfromdate, Date_Added, Suspended
    INTO @MonthYr
    FROM dibby.tbl_Aff_products

    Regards,
    Phil.
    Contact Us here: BSS Details
    Remember; the grass is never greener on the other side, merely where you tend to it.

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Jun 2006
    Posts
    628
    Thanks
    7
    Thanked 70 Times in 67 Posts
    Quote Originally Posted by Renners View Post
    I'm trying to get a stored procedure to work that will copy over the clickthrough and display details from my main database to a new table named based on (at the monent) the month& & year. I can get the name I need for the table however have lucked out in getting it to create the table simply getting an error when using the variable @MonthYr as the table name.

    I've shown my code below, any offers on what the issue is?

    Declare @MonthYr varchar(14)
    Declare @StatsMonth datetime
    Declare @StatsYear varchar(8)

    Set @StatsMonth=month(GetDate())
    Set @StatsYear=CAST((year(getdate()) % 100) AS CHAR(4))
    Set @MonthYr='Stats_'+Cast(@StatsMonth as Varchar(3))+Cast(@StatsYear as varchar(4))


    SELECT Prod_ID, Product_Name, Displayed_Count, Clickedcount, validtodate, validfromdate, Date_Added, Suspended
    INTO @MonthYr
    FROM dibby.tbl_Aff_products

    Regards,
    Phil.
    You should be able to it with dynamic sql, eg

    declare @sql varchar(255)
    set @sql = 'select ... into ' + @monthyr + ' from...
    exec(@sql)

    As you probably know dynamic sql isn't usually the most efficient way to go but it should be fine for this job

    Cheers,
    Jon

  3. The Following User Says Thank You to jonsp For This Useful Post:

    Renners (15-01-10)

  4. #3
    Big Member

    Status
    Offline
    Join Date
    Jan 2004
    Location
    Surrey
    Posts
    273
    Thanks
    50
    Thanked 23 Times in 14 Posts
    Quote Originally Posted by jonsp View Post
    You should be able to it with dynamic sql, eg

    declare @sql varchar(255)
    set @sql = 'select ... into ' + @monthyr + ' from...
    exec(@sql)

    As you probably know dynamic sql isn't usually the most efficient way to go but it should be fine for this job

    Cheers,
    Jon
    Thanks Jon, that did it.

    Declare @command varchar(500)
    set @command='SELECT Prod_ID, Product_Name, Displayed_Count, Clickedcount, validtodate, validfromdate, Date_Added, Suspended
    INTO '+@MonthYr+' FROM dibby.tbl_products'
    exec(@command)

    Regards,
    Phil.
    Contact Us here: BSS Details
    Remember; the grass is never greener on the other side, merely where you tend to it.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 29-07-10, 09:36 PM
  2. Correct tracking procedure for TD
    By Stellar in forum TradeDoubler
    Replies: 2
    Last Post: 01-06-06, 12:53 PM
  3. Pending Explain Plse - Jamster?
    By musicfactory in forum TradeDoubler
    Replies: 5
    Last Post: 18-05-05, 04:26 PM
  4. Affiliate links stored in a database
    By Nigel in forum Programming
    Replies: 4
    Last Post: 07-01-04, 01:46 PM
  5. Compliants procedure?
    By freebieholics in forum Affiliate Marketing Lounge
    Replies: 19
    Last Post: 20-06-03, 07:01 PM

Bookmarks

Posting Permissions

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

Content Relevant URLs by vBSEO 3.5.0 RC2