Forum Replies Created

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

  • RE: replace null with another column

    Brandie Tarvin (1/4/2017)


    I like CASE personally because it allows me to alter values being returned (or add new information) where as COALESCE just returns the original value.

    But you can manipulate...

  • 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...

  • 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

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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 ...

  • 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

  • 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,...

  • 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...

  • 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. ...

  • 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...

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