insert

  • declare @year char(4)

    set @year = '2007'

    declare @dat datetime

    set @dat='1/1/'+@year +''

    declare @i int

    set @i=0

    while @i<=11

    begin

    select

    datepart(yy,@dat )as Year,DATENAME ( mm,@dat )AS Month

    set @dat=DATEADD (mm , 1, @dat )

    set @i=@i+1

    End

    i just need to know how can i create #temp table and insert the results from this query into it

  • CREATE TABLE #tempdates

    (

    TempYear CHAR(4),

    TempMonth VARCHAR(15)

    )

    declare @year char(4)

    set @year = '2007'

    declare @dat datetime

    set @dat='1/1/'+@year +''

    declare @i int

    set @i=0

    while @i<=11

    begin

    INSERT INTO #tempdates

    (

    TempYear,

    TempMonth

    )

    select

    datepart(yy,@dat )as Year,DATENAME ( mm,@dat )AS Month

    set @dat=DATEADD (mm , 1, @dat )

    set @i=@i+1

    End

     

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]

  • Curious, Best, but when are you going to start doing your OWN work insterad of relying on the good nature of the people who use this site?

    If you would take the time to read BOL and pick up a couple of good SQL books, you would not have to ask for so much help.

  • what is your problem do me a favour dont answer if you dont want to and dont even come  and read my post if it bothers you so much

  • I am more than willing to help, but I am not the only one who is start to question helping you.  I have yet to see you put anything up to show you have truely tried to solve a problem yourself before asking for help.  Also, when general help has been given, you ignore it, and instead continue trying to find someone else to do your work for yourself.

    I have given you several assists that were general in nature, and never saw anything back from you to indicate that you had tried to solve the problem or if you still had problems what you had done to that point and what your efforts had accomplished.

    Asking people to do your work for you does you no good.  My telling you to invest some time and money to help yourself is actually in the best interest of everyone on this site because ity helps you become more knowledgeable and perhaps bring you to the point where instead of always asking for help, you can actually start helping others.  If you don't see a benefit in that, I am sorry.

  • The problem is that both temp tables and insert statements are very thoroughly documented in BOL, and you haven't shown a single line of code that demonstrates you've even given a half-hearted attempt at resolving it yourself. If you posted your attempts, the errors you got when running them, etc., you'd get no grief from Lynn or anyone else, and would likely have your answers within a few minutes.

    Most people who ask questions here (okay, everyone except you from what I've seen) are attempting to actually learn. Until you start sending us your paychecks or class credits, depending on the nature of the work we're doing for you, you'll continue to get grief when you simply want everything handed to you with zero effort on your part, and with no reason to believe that you won't simply ask the same question again next time the same problem crops up wherever you are.

  • To further the point David has made, not only are temp tables in insert statements documented in BOL, they are T-SQL fundamentals.  Many of the posts that come from you are asking for such basics as create a temp table, insert rows into a table, create a stored procedure that accepts parameters, etc. that it baffles me that after all this time you cannot perform these tasks without help.  I understand that there can be a certain level of 'greenness' to someone so I am happy to help out with such basic fundamental questions, but as David stated, it appears to us that you put zero effort into doing any of these basic tasks yourself.  If you cannot create a table and insert rows into it after this long at working with SQL Server, you should consider a career change.  It is not only unfair for us to do ALL of your work; it is extremely unfair to whomever is paying you that you have no desire to learn.  You may think that simply posting your stuff to this forum is saving you time, but anyone with a basic understanding of T-SQL could have solved your current problem in the amount of time it took you to post it to the forum.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply