• Abu Dina (11/19/2013)


    dwain.c (11/18/2013)


    Abu Dina (11/18/2013)


    Ah! Then you need to be introduced to the INTO Clause 😉

    A couple of caveats to using this technique:

    - All columns created will default to allow NULL values.

    Not sure I understand this, just tried the below:

    CREATE TABLE SCCTest (Col1 INT NOT NULL, Col2 INT NULL)

    INSERT INTO SCCTest(Col1, Col2)

    VALUES (1, 2)

    SELECT * INTO #SCCTest FROM SCCTest

    INSERT INTO #SCCTest (Col1, Col2)

    VALUES (NULL, 3)

    Msg 515, Level 16, State 2, Line 1

    Cannot insert the value NULL into column 'Col1', table 'tempdb.dbo.#SCCTest____________________________________________________________________________________________________________0000000007C0'; column does not allow nulls. INSERT fails.

    The statement has been terminated.

    Abu - That's an interesting result. Perhaps in my case the NOT NULL attribute only occurred because the SELECT query is more complicated so the INTO can't inherit the column attributes.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St