Forum Replies Created

Viewing 15 posts - 6,541 through 6,555 (of 8,731 total)

  • RE: Will the following procedure provide accurate sorting data each time with millions of records without a time field ?

    I forgot to mention that the CTE and ROW_NUMBER functions are not needed at all if you change to ORDER BY with OFFSET and FETCH options.

    The MAXDOP option might give...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: counting / group by confusion

    inevercheckthis2002 (4/25/2014)


    Luis Cazares (4/25/2014)


    More than a simple order by is needed....]

    Luis,

    Thank you very much for the solution and for the reference.

    You're welcome. Be sure to understand how the code works...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Will the following procedure provide accurate sorting data each time with millions of records without a time field ?

    Speaking about bad coding habits :crazy:

    Your code will allow sql injection. You need to parametrize your query.

    You will construct your conditions like this:

    if (@Date <> 0)

    Begin

    ...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Will the following procedure provide accurate sorting data each time with millions of records without a time field ?

    ROW_NUMBER is not designed to return data in certain order (even if it returns the rows in order most of the times when dealing with 10 rows). Your query is...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: counting / group by confusion

    More than a simple order by is needed. You need to use CROSS TABS (or pivot if you want to complicate yourself :-P).

    Here's a nice article on them: http://www.sqlservercentral.com/articles/T-SQL/63681/

    And here's...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Will the following procedure provide accurate sorting data each time with millions of records without a time field ?

    You can't guarantee and order if you don't have an ORDER BY in your query. If you have repeated values, the order won't be guaranteed either.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: SQL Design Question

    I would suggest that you normalize your tables and have an additional table for the telephone numbers.

    What would happen if an employee has more than one cell phone? Or several...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Error in pivot statement

    klbaiju 94581 (4/25/2014)


    Hi friend iam very eager to your reply.

    You need to understand that people are in different timezones. It was 4am when you posted your reply.

    To get the day...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: recursive queries - parent child

    You need to unpivot your table.

    An easy way is to use CROSS APPLY and VALUES clause.

    SELECT ParentID

    ,Child

    ,NULLIF(ParentID-1, 0) AS ParRel

    FROM #TestTable t

    CROSS...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: T-SQL - How to get one row on a table witjh multiple records

    Remove ",catalog.datfin" from GROUP BY.

    If you include it in the group by, you'll getting the minimum value for each date and that will be each date.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: t-sql 2012 with implicit join

    That code is full of syntax errors. Missing conditions on your JOINs and ON used more than once.

    BTW, your subquery might give you an error if more than one year...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Subquery returned more than 1 value error

    Have you checked if you have any triggers on finalTbl (I assume that might not be the real name)?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Error in pivot statement

    You need to include it in your subquery when creating the pivot. Something like this:

    from (

    select t.Month_date,b.tour_date,m.bus_id,b.[status]

    from #bus_master m

    LEFT

    JOIN #Busdetails b ON m.bus_id = b.bus_id

    left outer join #temp t on...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Nvarchar to Float

    Sean Lange (4/24/2014)


    Here we created a nonSARGable predicate by casting the column but we also added an implicit conversion because now that our previous integer value has been cast a...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Nvarchar to Float

    Number 9 and 10 are just wrong. Taking aside that number 9 suggest to make a query non-SARGable to "improve server statistics", both examples rely...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 15 posts - 6,541 through 6,555 (of 8,731 total)