Forum Replies Created

Viewing 15 posts - 301 through 315 (of 1,923 total)

  • RE: Do not want to use a cursor but how.....

    depends on what the SP FRACAS_TicketVsEvent does

  • RE: Find Customers Who Bought "A" and "B" But Not "C" (SQL Spackle)

    Toby Harman (3/29/2012)


    Hate to point this out, but ColdCoffee's approach is returning inaccurate results.

    Specifically, it returns customers 6 and 7 from the original test data.

    That proves why my code...

  • RE: rmove leading zeros

    GSquared (3/29/2012)


    You don't actually need the case statement:

    SELECT STUFF(Y, 1, PATINDEX('%[^0]%', Y)-1, '')

    FROM (VALUES('123'),('0123'),('000123')) AS X(Y);

    Works just fine.

    Yeah Gus, it occured to me just after posting the code. Thanks for...

  • RE: Find Customers Who Bought "A" and "B" But Not "C" (SQL Spackle)

    How about this?

    ; WITH CTE AS

    (

    SELECT P.CustomerID

    , Indicator1 = CASE WHEN P.ProductCode IN('A') THEN 0

    WHEN P.ProductCode IN('C') THEN -1

    END

    ,...

  • RE: rmove leading zeros

    THis?

    SELECT Tab.String

    ,NewStr = CASE WHEN LEFT(Tab.String,1) = '0' THEN STUFF (Tab.String,1, PATINDEX('%[1-9]%',Tab.String) -1 , '' )

    ...

  • RE: rmove leading zeros

    This?

    SELECT Tab.String

    ,NewStr = CASE WHEN LEFT(Tab.String,1) = '0' THEN STUFF (Tab.String,1,1,'')

    ...

  • RE: Running Totals on PIVOT in T-SQL

    Can you post the query you tried ?

    And also, can you post the data in readily-consumable format? I cannot download content at my office.

    Please read here on how ro format...

  • RE: Running Totals on PIVOT in T-SQL

    GROUP BY with ROLLUPs may be?

  • RE: count(-1) is working

    Interestingly, this yields 0 for a table that contains no null values and also uses COUNT(*) as the StreamAggregate operator. (It is also once noted by Paul White, but i...

  • RE: count(-1) is working

    Sean Lange (3/29/2012)


    Try this examples to know how COUNT(*) and COUNT(1) can vary depending the data contained in the columns.

    You have me a bit confused by this. Count(*) and Count(1)...

  • RE: Find Customers Who Bought "A" and "B" But Not "C" (SQL Spackle)

    chintan.j.gandhi (3/29/2012)


    How about this? Although i agree query might get longer when there would be more than 3 items

    SELECT DISTINCT CustomerID

    FROM #Purchase P

    WHERE EXISTS...

  • RE: Vertical to Horizontal

    LIke this

    IF OBJECT_ID('TempDB..#Temp') IS NOT NULL

    DROP TABLE #Temp;

    GO

    ;

    CREATE TABLE #Temp

    (

    Store INT

    ,PhoneNr VARCHAR(20)

    )

    ;

    INSERT INTO #Temp (Store,PhoneNr)

    ...

  • RE: Vertical to Horizontal

    Look up PIVOT in SQL MSDN Online.

  • RE: count(-1) is working

    dwain.c (3/29/2012)


    ColdCoffee:

    So I think what you're saying (I am not an XML Plan-master, nor even a Paduan) is that COUNT(column_name) returns the number of rows that have non-NULL values? ...

  • RE: count(-1) is working

    dwain.c (3/28/2012)


    My understanding is that it doesn't matter whether you count all columns (*), a single column or a scalar value, the count returned is always the number of rows...

Viewing 15 posts - 301 through 315 (of 1,923 total)