Forum Replies Created

Viewing 15 posts - 1,306 through 1,320 (of 8,731 total)

  • RE: UNPIVOTING Columns

    Maybe something like this would work.

    SELECT COL1, COL2, NEW_COLUMN
    FROM TABLE
    CROSS APPLY (VALUES('COL3', CAST( COL3 AS varchar(100))),
           ('COL4', CAST( COL4 AS varchar(100))),
           ('COL5',...

    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: Convert Horizontal Table to Vertical Table?

    This should be efficient as it reads the table only once.

    WITH ClockCounts AS(
      SELECT COUNT(*)   AS ClockIn ,
        COUNT(EndTime) AS ClockOut
      FROM...

    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: How to use 'between' in CASE statement?

    Even simpler. You're basically trying to query the current month for the day before.

    DECLARE @StartDate date = DATEADD(mm, DATEDIFF( mm, 0, GETDATE() - 1), 0);
    DECLARE...

    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: (Quickly) Delete records from a table, with condition

    Wild idea:
    Why don't you simply update the table instead of deleting and re-inserting?

    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: How to use 'between' in CASE statement?

    Charmer - Friday, May 5, 2017 8:01 AM

    Yeah I knew that syntax was wrong, Thom. That's how my requirement is. Based 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: Drop/Create objects versus Alter

    jonathan.crawford - Friday, May 5, 2017 8:19 AM

    Grant Fritchey - Friday, May 5, 2017 7:55 AM

    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: how to change floor function to Round

    Actually, ROUND uses 3 parameters. The third parameter indicates if it needs to truncate or round.
    There's a difference on how FLOOR and ROUND work with negatives.
    I explain...

    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: How to build a field name in a select statement

    You also want to use  QUOTENAME() to handle complex names for your columns or objects.

    DECLARE @Field_suffix char(1);
    DECLARE @sql varchar(MAX);

    SET @Field_suffix = '1';

    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 to reduce pain in my eyes, i.e. to find out which values are different in 2 tables ( out of 155 column(s) , both tables with identical DDL and same # of rows

    Try this:

    DECLARE @sql nvarchar(max)
    SELECT @sql = N'SELECT H.UserID' + CHAR(10)
      + STUFF(( SELECT CHAR(10) + CHAR(9) + ',ISNULL( NULLIF( H.' + QUOTENAME(COLUMN_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: COMPUTED COLUMN needing to retain value

    Zososql - Wednesday, May 3, 2017 10:37 PM

    Even if the value in confirmDate changes after it gets inserted with the computed column,...

    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: Grabbing sets less than an arbitrary number; not quite a bin packing problem

    drew.allen - Thursday, May 4, 2017 11:44 AM

    You need to include your table name in the ORDER BY clause in windowed function...

    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: Grabbing sets less than an arbitrary number; not quite a bin packing problem

    Could you be missing the ROWS clause in the OVER()?

    DECLARE @MaxRecords int = 500;

    WITH MyLimits
    AS
    (
    SELECT SUM(COUNT(colz.OBJECT_ID)) OVER( ORDER...

    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: Is there a better way to do this sort of Case with counts, trying to re-organize to run faster

    Thom A - Thursday, May 4, 2017 8:19 AM

    Fixed your formatting for you...
    SELECT count(*),
           (CASE WHEN wfstate =0...

    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: Today's Random Word!

    Ed Wagner - Wednesday, May 3, 2017 11:40 AM

    Hugo Kornelis - Wednesday, May 3, 2017 11:33 AM

    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: Today's Random Word!

    Ed Wagner - Wednesday, May 3, 2017 6:41 AM

    ManicStar - Wednesday, May 3, 2017 6:09 AM

    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 - 1,306 through 1,320 (of 8,731 total)