Forum Replies Created

Viewing 15 posts - 826 through 840 (of 1,246 total)

  • RE: String Updation in a formula of a table -Query required

    Anandkumar-SQL_Developer (9/16/2016)


    Solution :

    select [KPI ID]

    ,[KPI Name],

    [KPIFormula] = case when [kpi id] = 'SA2' then '[QW1]+[SA2]+[BG7]'

    when [kpi id] = 'XS3' then '[QW1]+[BG7]'

    when [kpi id] = 'BG7' then 'BG7' else [kpi id]end

    ...

  • RE: Can someone try this?

    ken.trock (9/15/2016)


    Hello. I had this weird thing happen on SQL 2012 SP2 and SP3.

    CREATE TABLE dbo.EmployeeHistory (StartDate SMALLDATETIME, EndDate SMALLDATETIME, NativeWorkerID VARCHAR(255), EmployeeID VARCHAR(20))

    CREATE TABLE dbo.EH_NativeWorker_Dups(NativeWorkedID VARCHAR(255))

    SELECT DISTINCT EmployeeID, NativeWorkerID...

  • RE: SQL Code QA

    The Dixie Flatline (9/15/2016)


    I don't think I've ever done a RIGHT JOIN in production. :ermm:

    Ditto... Keep the "left table" to the left...

  • RE: delete millions of rows

    Here's another good way to handle massive deletes... No down time for the affected table and works especially well if the table is schema-bound by another object...

    Partition SWITCH...

    USE tempdb;

    GO

    --================================================================

    --...

  • RE: Convert Columns to Rows

    j-1064772 (9/14/2016)


    tripleAxe (9/14/2016)


    How about this.....

    SELECT 'AZ' [STATE], SUM(AZ) [VAL] FROM EXAMPLE

    UNION ALL

    SELECT 'NY' [STATE], SUM(NY) [VAL] FROM EXAMPLE

    UNION ALL

    SELECT 'PA' [STATE], SUM(PA) [VAL] FROM EXAMPLE

    Yes, this was my question from...

  • RE: Convert Columns to Rows

    tripleAxe (9/14/2016)


    How about this.....

    SELECT 'AZ' [STATE], SUM(AZ) [VAL] FROM EXAMPLE

    UNION ALL

    SELECT 'NY' [STATE], SUM(NY) [VAL] FROM EXAMPLE

    UNION ALL

    SELECT 'PA' [STATE], SUM(PA) [VAL] FROM EXAMPLE

    That's going to do 3 separate pulls...

  • RE: Convert Columns to Rows

    The Dixie Flatline (9/14/2016)


    Is it just me, or is the syntax for PIVOT/UNPIVOT *much* harder to follow than cross-tab or APPLY VALUES ?

    Agree 100%... PIVOT & UNPIVOT were solutions to...

  • RE: String Updation in a formula of a table -Query required

    Either way, yours is clearly better (well done sir!). Considering the sample size, I didn't bother looking the the timings. It's just not large enough to get accurate times and...

  • RE: String Updation in a formula of a table -Query required

    Looking at execution plans... Chris's script is far more efficient than mine... Use his script.

    Just an FYI... Chris and I are using the same split function. We just gave them...

  • RE: Convert Columns to Rows

    drew.allen (9/14/2016)


    The phrase is "moot point".

    Fixed. 😀

    Just looking at the execution plans... Summing 1st is quite a bit more efficient...

    IF OBJECT_ID('tempdb..#Example','U') IS NOT NULL

    DROP TABLE #Example;

    CREATE TABLE #Example (

    id INT,

    AZ...

  • RE: String Updation in a formula of a table -Query required

    This should do what you're asking...

    -- Test data --

    IF OBJECT_ID('tempdb..#OrigTable', 'U') IS NOT NULL

    DROP TABLE #OrigTable;

    CREATE TABLE #OrigTable (

    KPI_ID CHAR(3),

    KPI_NAME CHAR(3),

    KPIFORMULA VARCHAR(1000)

    );

    INSERT #OrigTable (KPI_ID, KPI_NAME, KPIFORMULA) VALUES

    ('QW1', 'ABC', 'No...

  • RE: Convert Columns to Rows

    Jeff Moden (9/14/2016)


    Although that's great use of the CROSS APPLY trick to unpivot, the output isn't the same as the requested output, which appears to be a sum for each...

  • RE: rotation by percentage rather than equal rotation of ISCI values

    If you'd like some help, take a look at the link in Drew's signature to see how to post so that you have the best chance of getting an answer.

    Forum...

  • RE: Convert Columns to Rows

    TheSQLGuru (9/13/2016)


    CROSS APPLY VALUES #FTW!! Nicely done Jason. 🙂

    TY Sir! 😀

  • RE: Convert Columns to Rows

    dallas13 (9/13/2016)


    Thanks

    No problem. 🙂

Viewing 15 posts - 826 through 840 (of 1,246 total)