Forum Replies Created

Viewing 15 posts - 2,041 through 2,055 (of 4,085 total)

  • RE: replace null with another column

    komal145 (1/4/2017)


    I have Firstname , firstname 1 , firstname 2 ,firstname3

    If firstname is null thne firstname1 , if firstname1 is also null then Firstname2 ...will the case will work ?

    Case...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: How to create error conditions inside function

    Both THROW and RAISERROR cause side effects and user-defined functions cannot cause side effects, so you cannot use a THROW or RAISERROR in a UDF.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Report Showing Month with Highest Count

    Alan.B (1/3/2017)


    drew.allen (1/3/2017)


    Alan.B (1/3/2017)


    This wont work because you can't nest aggregates like this so we'll have to break out the RANK Window Function like so (including sample data so you...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Renaming fields and combining them into one column

    Luis Cazares (1/3/2017)


    Keeping Phil's simple formula:

    SELECT name = concat(First_Name, ' ', Last_Name),

    Sports = STUFF(iif(Football = 'Y', '; Football','') + iif(Soccer = 'Y', '; Soccer','') + etc, 1, 2, '')

    FROM...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Report Showing Month with Highest Count

    Alan.B (1/3/2017)


    This wont work because you can't nest aggregates like this so we'll have to break out the RANK Window Function like so (including sample data so you can just...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Renaming fields and combining them into one column

    I prefer the XML concatenation technique. I also put a leading delimiter instead of a trailing delimiter, because you always know exactly where to find the one to remove...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Finding First Occurrence in a given year

    TheSQLGuru (1/3/2017)


    With your requirements amendment I think Drew's modification to my query should get you what you want.

    Actually, it was a modification of my original query. I didn't realize...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Finding First Occurrence in a given year

    TheSQLGuru (1/3/2017)


    TheSQLGuru (1/3/2017)


    It would be helpful to have sample data and expected output. But I am thinking something like this:

    select year(awarddate), employeeid, min(awarddate)

    from sometable

    where awardflag = 1

    group by awarddate, employeeid

    I...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Finding First Occurrence in a given year

    jon.wilson (1/3/2017)


    Sample data provided in previous post expected output would be

    Year Number of First Time Award recipients

    2012 40

    2013 ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Finding First Occurrence in a given year

    It sounds like you want something like the following.

    SELECT employee_id

    FROM awards

    GROUP BY employee_id

    HAVING YEAR(MIN(award_dt)) = YEAR(GETDATE())

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Where to place WITH (NOLOCK) ?

    Unless you are okay with dirty reads, e.g., skipped records or repeated records, NOWHERE. WITH (NOLOCK) is not a magic "go faster" hint. It comes at a cost,...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Summarising Postcodes into Banding

    This is just a gaps and islands problem.

    ;

    WITH Postcode_groups AS (

    SELECT Postcode, Rating, ROW_NUMBER() OVER(ORDER BY Postcode) - ROW_NUMBER() OVER(PARTITION BY Rating ORDER BY Postcode) AS Grp

    FROM #SamplePostcodes

    --ORDER BY Postcode;

    )

    SELECT...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Excel source having more than 255 characters

    gward 98556 (2/27/2014)


    Don't forget that whenever you ever move the package to another server it will fail again until you or a colleague finds out about the registry hack. ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: First occurrences

    watto84 (12/29/2016)


    I worked it out 🙂

    As you suggested, it just needed a slight modification to "order by" in the below section of the code:

    ROW_NUMBER() OVER (PARTITION BY Game, Team ORDER...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: SQL beginner needs assistance! ( I know, I know, GREAT! Right?? lol)

    Actually ACCT IN (111, 222, 555, etc.) is shorthand for ACCT = 111 OR ACCT = 222 OR ACCT = 555, etc., so they are equivalent in terms of performance.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 2,041 through 2,055 (of 4,085 total)