Forum Replies Created

Viewing 15 posts - 3,676 through 3,690 (of 8,731 total)

  • RE: Using window functions to subtract one column with another

    I'm sorry, I included an aggregation where I shouldn't.

    SELECT id

    ,knt

    ,dt

    ...

    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: Need help on using a single SELECT query to transform a table, thanks.

    Now I see what's going on. Since you didn't post your sample data in a consumable way even if you've been around a long time, I'll just point you to...

    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: Using window functions to subtract one column with another

    Maybe something like this:

    SELECT id

    ,knt

    ,dt

    ,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: Transposing Columns to rows

    I prefer to do it using CROSS APPLY and table constructors. Here's an article on that: http://www.sqlservercentral.com/articles/CROSS+APPLY+VALUES+UNPIVOT/91234/

    IF OBJECT_ID('tempdb..#test') IS NOT NULL

    DROP TABLE #test

    CREATE TABLE #test (colx...

    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: Need help on using a single SELECT query to transform a table, thanks.

    What have you tried? Where's the sample data and expected results?

    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: Converting a date

    PhilPacha (12/4/2015)


    Thanks for the update about datetime --> date; I wasn't aware of that.

    I just wanted to include a test because people shouldn't just trust anything they read online. 😉

    --=====...

    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: Converting a date

    PhilPacha (12/4/2015)


    A CAST on the database column would likely preclude the use of an available index, while using the native values would allow index usage, if available. The >= and...

    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: 4 Table Cross Join

    First of all, you need to reference the CTE through a SELECT statement. Something like this:

    --Insert a reservation for a key during specific dates

    WITH Dates AS (

    SELECT

    [Date] = CONVERT(date,'20151127')

    UNION ALL...

    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: Are the posted questions getting worse?

    Jeff Moden (12/4/2015)


    Is anyone else not getting notifications from posts? I haven't gotten a 1 since Nov 29th. I sent an email to the webmaster but no response...

    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 server conversion error issue

    FridayNightGiant (12/4/2015)


    You could use a CTE or subquery to initially select the rows with valid dates...

    Actually, that's also prone to error. Even with a view, the error could appear.

    I like...

    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: Are the posted questions getting worse?

    I don't remember most of Doof's inventions, but my favorites are the Inator-inator and Norm. 😀

    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: Function to find and replace from a string where like or contains

    Sean Lange (12/3/2015)


    Alan.B (12/3/2015)

    I am curious about a couple things here.

    Why MAX(c)?

    (MAX(c),'No Colour')

    To always return a row, either with a value or a null. I might have done it different,...

    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 QUERY

    Here's your sample data in a proper format so anyone can test a solution. Please post it this way next time.

    CREATE TABLE TableA(

    personid int,

    ...

    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: SELECT COUNT WITH CONDITION IN OPTMISE WAY

    A filtered index might do the trick, but only for the condition defined to filter the index. With that, you simply query sys.dm_db_partition_stats, something like this:

    SELECT SUM (row_count)

    FROM sys.dm_db_partition_stats s

    JOIN...

    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: Function to find and replace from a string where like or contains

    Can you give some examples of your inputs and ouputs?

    You added a lot of work when it's not needed. Your function can be reduced to a single statement.

    Do you have...

    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 - 3,676 through 3,690 (of 8,731 total)