Forum Replies Created

Viewing 15 posts - 5,236 through 5,250 (of 10,144 total)

  • RE: Need Help in Selecting Random and Non Sequential Data

    Since the numbers are no longer random, why not break the randomness rules again and use this very simple algorithm?

    ;WITH SampleData AS (

    SELECT ID = RIGHT('0'+CAST(n AS VARCHAR(2)),2)

    FROM (SELECT TOP...

  • RE: Catch Data between symbols in SQL

    dwain.c (2/8/2013)


    vinu512 (2/7/2013)


    ...

    8 seconds? What are you using? A netbook with an Atom processor?

    ............

    It must have been. That or a wristwatch. It resolved something like 100000 rows in...

  • RE: Finding patterns in rows (date ordered)

    greg.bull (2/8/2013)


    OK best I can think of then is to use a calendar table to plug holes in the data - processing each staffid one by one in a supervisory...

  • RE: Catch Data between symbols in SQL

    vinu512 (2/7/2013)


    hi Chris, it definitely runs like a Rocket. It would be really nice if you could explain the following code :

    SELECT df = LEFT(b.AllLevels, CHARINDEX('»',b.AllLevels,1)-1)

    UNION ALL

    SELECT df =...

  • RE: Catch Data between symbols in SQL

    Sean Lange (2/7/2013)


    How about using the DelimitedSplit8k? This seems to be super fast to me.

    Select Id,

    MAX(Case When ItemNumber = 1 Then Item Else '' End) As...

  • RE: Nested SQL Query - % of Group Total

    mjbkm (2/7/2013)


    OK, I was closer.

    Also, I applied this to my live query and I got this error:

    Divide by zero error encountered.

    -- replace this

    SELECT Percentage = CAST(q.Amount*1.00/q.GroupTotal AS NUMERIC(5,2))

    -- with this...

  • RE: Nested SQL Query - % of Group Total

    Sean Lange (2/7/2013)


    ChrisM@Work (2/7/2013)

    Actually I misread your post Sean - thought you had used the "aggregate in a derived table" trick, or I wouldn't have posted this!

    I am not sure...

  • RE: Nested SQL Query - % of Group Total

    mjbkm (2/7/2013)


    Got it!!!!!!!!

    ...

    Not quite...

    WITH SampleData ([Group], [Type], Amount) AS (

    SELECT 'Dog', 'Typea', 1 UNION ALL

    SELECT 'Dog', 'Typeb', 2 UNION ALL

    SELECT 'Dog', 'Typec', 3 UNION ALL

    SELECT 'Cat', 'Typea', 10...

  • RE: Nested SQL Query - % of Group Total

    mjbkm (2/7/2013)


    ChrisM@Work (2/7/2013)


    Aggregate Amount by Group and type, then feed the result into Sean's original query.

    That is where I was stuck before. How would I change this?

    SELECT

    [Group],

    [Type],...

  • RE: If or case staement in a where?

    It can be easier to visualise complex filters by switching them into a CROSS APPLY for testing. Shamelessly nicking Orlando's setup, it might look like this;

    USE tempdb;

    IF OBJECT_ID(N'tempdb..#CLIENT_IDENTIFIER_TYPE') IS NOT...

  • RE: Nested SQL Query - % of Group Total

    Aggregate Amount by Group and type, then feed the result into Sean's original query.

  • RE: Nested SQL Query - % of Group Total

    mjbkm (2/7/2013)


    This is working great too. What if I add multiple types per animal in first. How do I group and total first and then get the same...

  • RE: Nested SQL Query - % of Group Total

    Sean Lange (2/7/2013)


    ChrisM@Work (2/7/2013)


    ;WITH SampleData ([Group], [Type], Amount) AS (

    SELECT 'Dog', 'Typea', 1 UNION ALL

    SELECT 'Dog', 'Typeb', 2 UNION ALL

    SELECT 'Dog', 'Typec', 3 UNION ALL

    SELECT 'Cat', 'Typea', 10 UNION ALL

    SELECT...

  • RE: Nested SQL Query - % of Group Total

    ;WITH SampleData ([Group], [Type], Amount) AS (

    SELECT 'Dog', 'Typea', 1 UNION ALL

    SELECT 'Dog', 'Typeb', 2 UNION ALL

    SELECT 'Dog', 'Typec', 3 UNION ALL

    SELECT 'Cat', 'Typea', 10 UNION ALL

    SELECT 'Cat', 'Typeb', 20

    )

    SELECT...

  • RE: Only NUMBERS

    carlosaamaral (2/7/2013)


    OPS... living and learning ....

       changed to level 100 - perfect ..

    ; WITH THE Strings (

    SELECT String = 'AJKY.GSEFD6, 7345535HNB, BBN4343.434'

    UNION ALL SELECT '11-908 / *** 88AB; '

    )

    SELECT

    s.String,

    x.NewString

    FROM Strings...

Viewing 15 posts - 5,236 through 5,250 (of 10,144 total)