Forum Replies Created

Viewing 15 posts - 31 through 45 (of 98 total)

  • RE: Get month names ordered using recursion

    ChrisM@home (3/23/2012)


    Here's one way of limiting the rowcount:

    DECLARE @pString VARCHAR(8000), @pDelimiter CHAR(1)

    SET @pString = 'one,TWO,THREE,FOUR,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,twenty one,twenty two,twenty three,twenty four'

    SET @pDelimiter = ','

    SELECT

    ItemNumber = CAST(0 AS BIGINT),

    Item = LEFT(@pString,...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    Jeff Moden (3/22/2012)


    ChrisM@Work (3/19/2012)


    This is pretty fast too:

    SELECT n = (n1 + n2 + n3 + n4)

    FROM (((VALUES (0),(100),(200),(300),(400),(500),(600),(700),(800),(900)) t3 (n3)

    CROSS JOIN (VALUES...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    tobe (3/16/2012)


    Simple, faster and still doesn't require tables.

    select monthNumber

    , DATENAME(MONTH,DATEADD(MONTH,monthNumber,0)- 1) MonthName

    from ( values (1), (2), (3), (4), (5), (6),...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    Jeff Moden (3/15/2012)


    My point is that you do need to kill the flys or the resulting swarm will result in posts like "Why is my database running so slow?" ...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    Jeff Moden (3/14/2012)


    the sqlist (3/13/2012)


    CTE is nice at times but we have to keep in mind that it doesn't work on all platforms so I would avoid it

    I hope...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    Make it a view to be easier:

    create view vwMonths as

    select

    N+1 as month_nr,

    datename(mm,(dateadd(mm,N,'2012-01-01'))) as month_name

    from

    (

    select 0 as N union

    select 1 as N union

    select...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    Here:

    select

    N+1 as month_nr,

    datename(mm,(dateadd(mm,N,'2012-01-01'))) as month_name

    from

    (

    select 0 as N union

    select 1 as N union

    select 2 as N union

    select 3 as N union

    select...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Get month names ordered using recursion

    No offense but this should be an example of how NOT to do things in SQL server. Before writing anything we should make sure that we actually understand what we...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Simplify Large Queries with Temporary Tables, Table Variables and CTEs

    the sqlist (8/11/2011)


    amir.mochtar (8/10/2011)


    i created #tmp table when processing large of rows then i made index for some columns, those are often used in inquiry. Did i do right?

    The only...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Simplify Large Queries with Temporary Tables, Table Variables and CTEs

    amir.mochtar (8/10/2011)


    i created #tmp table when processing large of rows then i made index for some columns, those are often used in inquiry. Did i do right?

    The only problem with...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Simplify Large Queries with Temporary Tables, Table Variables and CTEs

    alen teplitsky (8/10/2011)


    could have been bugs in earlier versions of sql 2005 but i used to have problems with temp tables not being deleted. my indexing maintenance was a stored...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Simplify Large Queries with Temporary Tables, Table Variables and CTEs

    Patibandla (8/10/2011)


    @sqlist

    But with select into you cannot have an identity column , you have to use row_number otherwise , which may affect the performance when you are dealing with large...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Simplify Large Queries with Temporary Tables, Table Variables and CTEs

    martha-1063616 (8/10/2011)


    Why creating the tables.. sometimes you just do your temptable like this:

    select distinct CONVERT(nvarchar(30), (KO.a)) AS a,

    CONVERT(nvarchar(30), (KO.b)) AS b,

    Navn AS Name

    into#MyTempTable

    fromTable 1KO

    INNER JOINTable 2KU

    ONKO.NR...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Simplify Large Queries with Temporary Tables, Table Variables and CTEs

    A temporary table is available as long as the database connection with which it was executed is still open. If it is declared with the "##" prefix, it is a...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • RE: Introduction to Indexes: Part 3 – The nonclustered index

    Thus, my question:

    In the query

    SELECT *

    FROM table1 t1

    INNER JOIN table2 t2

    ON t1.col1 = t2.col1

    AND t1.col2 = t2.col2

    AND t1.col3 = t2.col3

    when I have three indexes, one each on col1, col2 and...

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

Viewing 15 posts - 31 through 45 (of 98 total)