Query Help

  • Hi All Experts,

    I am a newbie in SQL Server and would like your help on the following query.

    Please consider the below sample data

    /*

    I want to traverse through a loop. Loop starts with Coke/Fanta and Ends With HardDrink.

    After HardDrink it is neccessarily Coke or Fanta.

    Now over here i want the value from the column "value" for Pepsi.

    There can be a suituation where Pepsi can occur more then once in the loop between

    Coke/Fanta and HardDrink.

    */

    CREATE TABLE #TEMP (UserName varchar(20),Drink varchar(20),Value int,CreatedDate date)

    INSERT INTO #TEMP VALUES ('ABC','Coke',100,'2014-01-12') --Just one pepsi record in this loop would be displayed

    INSERT INTO #TEMP VALUES ('ABC','Fanta',50,'2014-01-13')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',50,'2014-01-14')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',75,'2014-01-18')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',36,'2014-01-20') -- No Pepsi in this loop so no pepsi record would be displayed

    INSERT INTO #TEMP VALUES ('ABC','XXX',45,'2014-01-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',75,'2014-02-04')

    INSERT INTO #TEMP VALUES ('ABC','XXX',96,'2014-02-06')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',12,'2014-02-10')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',93,'2014-02-22') -- 2 Pepsi in this loop but the one with the value 510 would be shown because it is latest

    INSERT INTO #TEMP VALUES ('ABC','XXX',101,'2014-02-22')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',150,'2014-02-23')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',510,'2014-02-24')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',175,'2014-02-25')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',136,'2014-02-26') --Since there is no end, Hence Either Fanta or Coke which ever latest record would be displayed. In this case Fanta

    INSERT INTO #TEMP VALUES ('ABC','XXX',145,'2014-02-27')

    INSERT INTO #TEMP VALUES ('ABC','XXX',175,'2014-02-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',196,'2014-03-01')

    INSERT INTO #TEMP VALUES ('ABC','XXX',112,'2014-03-02')

    INSERT INTO #TEMP VALUES ('ABC','XXX',193,'2014-03-03')

    SELECT * FROM #TEMP

    /*

    So my output would be like

    UserName DrinkValueCreatedDate

    ABC Pepsi502014-01-14

    ABC Pepsi5102014-02-25

    ABC Fanta1362014-02-26

    */

    I want to traverse through a loop. Loop starts with Coke/Fanta and Ends With HardDrink.

    After HardDrink it is neccessarily Coke or Fanta.

    Now over here i want the value from the column value for Pepsi.

    There can be a suituation where Pepsi can occur more then once in the loop between

    Coke/Fanta and HardDrink.

    So my output would be like

    UserName DrinkValueCreatedDate

    ABC Pepsi502014-01-14

    ABC Pepsi5102014-02-25

    ABC Fanta1362014-02-26

  • It's not clear to me what the transformation is that you're trying to achieve here. Also, iterating over names doesn't make a whole lot of sense. Are you trying to sum up the values of each drink type? are you trying to eliminate values from the set?

    Executive Junior Cowboy Developer, Esq.[/url]

  • I don't see what you're after either. Good job posting consumable DDL and sample data. Could you please explain the logic behind how you get the output you're trying to produce?

  • Ed Wagner (8/21/2014)


    I don't see what you're after either. Good job posting consumable DDL and sample data. Could you please explain the logic behind how you get the output you're trying to produce?

    Well the logic is to traverse through Coke/Fanta to HardDrink. In Between this if you find Pepsi Display it if not then dont display it. If there are multiple entries of Pepsi between (Coke or Fanta) to HardDrink then display the one which is latest, which we can find out with the help of createdDate column.

  • Quick though, first move towards an SQL set based solution is to change the word Loop to Group. Each Group starts with Coke/Fanta and ends in a HardDrink:doze:

    😎

    Here is an example to get you started, it is not a full solution.

    CREATE TABLE #TEMP (T_ID INT IDENTITY(1,1),UserName varchar(20),Drink varchar(20),Value int,CreatedDate date)

    INSERT INTO #TEMP VALUES ('ABC','Coke',100,'2014-01-12') --Just one pepsi record in this loop would be displayed

    INSERT INTO #TEMP VALUES ('ABC','Fanta',50,'2014-01-13')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',50,'2014-01-14')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',75,'2014-01-18')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',36,'2014-01-20') -- No Pepsi in this loop so no pepsi record would be displayed

    INSERT INTO #TEMP VALUES ('ABC','XXX',45,'2014-01-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',75,'2014-02-04')

    INSERT INTO #TEMP VALUES ('ABC','XXX',96,'2014-02-06')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',12,'2014-02-10')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',93,'2014-02-22') -- 2 Pepsi in this loop but the one with the value 510 would be shown because it is latest

    INSERT INTO #TEMP VALUES ('ABC','XXX',101,'2014-02-22')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',150,'2014-02-23')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',510,'2014-02-24')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',175,'2014-02-25')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',136,'2014-02-26') --Since there is no end, Hence Either Fanta or Coke which ever latest record would be displayed. In this case Fanta

    INSERT INTO #TEMP VALUES ('ABC','XXX',145,'2014-02-27')

    INSERT INTO #TEMP VALUES ('ABC','XXX',175,'2014-02-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',196,'2014-03-01')

    INSERT INTO #TEMP VALUES ('ABC','XXX',112,'2014-03-02')

    INSERT INTO #TEMP VALUES ('ABC','XXX',193,'2014-03-03')

    ;WITH DRINK_WEIGHT(WEIGHT_VAL,DRINK_NAME) AS

    (SELECT WEIGHT_VAL,DRINK_NAME FROM (

    VALUES (1,'Coke'),(2,'Fanta'),(3,'Pepsi'),(4,'XXX'),(5,'HardDrink')

    ) AS X( WEIGHT_VAL,DRINK_NAME))

    ,BASE_DATA AS

    (

    SELECT

    T_ID

    ,T.UserName

    ,T.Drink

    ,T.Value

    ,T.CreatedDate

    ,DW.WEIGHT_VAL

    FROM #TEMP T

    OUTER APPLY DRINK_WEIGHT DW

    WHERE T.Drink = DW.DRINK_NAME

    )

    SELECT

    BD.T_ID

    ,BD.UserName

    ,BD.Drink

    ,BD.Value

    ,BD.CreatedDate

    ,BD.WEIGHT_VAL

    FROM BASE_DATA BD

    DROP TABLE #TEMP;

  • Hi Eirikur ,

    Thanks for taking time out and replying.

    Still i am not able to move forward.

  • SELECT UserName, Drink, Value, CreatedDate

    FROM ( -- d

    SELECT UserName, Drink, Value, CreatedDate,

    rn = ROW_NUMBER() OVER(PARTITION BY grp ORDER BY CreatedDate DESC)

    FROM #TEMP t

    OUTER APPLY ( -- ou

    SELECT TOP 1 grp

    FROM (SELECT UserName, CreatedDate, grp = ROW_NUMBER() OVER(ORDER BY CreatedDate) FROM #TEMP WHERE Drink = 'HardDrink') ti

    WHERE ti.UserName = t.UserName

    AND ti.CreatedDate > t.CreatedDate

    AND t.Drink <> 'HardDrink'

    ORDER BY ti.CreatedDate ASC

    ) ou

    WHERE (t.Drink = 'Pepsi' AND grp > 0)

    OR (t.Drink IN ('Fanta','Coke') AND grp IS NULL)

    ) d

    WHERE rn = 1

    ORDER BY UserName, CreatedDate

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thank you very much Chris.

    Could i know your twitter handel, so that i can follow you.

    Best Regards.

  • Suppose if i decided to tweak my result as

    /*

    I want to traverse through a loop. Loop starts with Coke/Fanta and Ends With HardDrink.

    After HardDrink it is neccessarily Coke or Fanta.

    Now over here i want the value from the column "value" for Pepsi.

    There can be a suituation where Pepsi can occur more then once in the loop between

    Coke/Fanta and HardDrink.

    */

    CREATE TABLE #TEMP (UserName varchar(20),Drink varchar(20),Value int,CreatedDate date)

    INSERT INTO #TEMP VALUES ('ABC','Coke',100,'2014-01-12') --Just one pepsi record in this loop would be displayed

    INSERT INTO #TEMP VALUES ('ABC','Fanta',50,'2014-01-13')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',50,'2014-01-14')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',75,'2014-01-18')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',36,'2014-01-20') -- No Pepsi in this loop so DISPLAY THE RECORD WITH COKE/FANTA

    INSERT INTO #TEMP VALUES ('ABC','XXX',45,'2014-01-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',75,'2014-02-04')

    INSERT INTO #TEMP VALUES ('ABC','XXX',96,'2014-02-06')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',12,'2014-02-10')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',93,'2014-02-22') -- 2 Pepsi in this loop but the one with the value 510 would be shown because it is latest

    INSERT INTO #TEMP VALUES ('ABC','XXX',101,'2014-02-22')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',150,'2014-02-23')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',510,'2014-02-24')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',175,'2014-02-25')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',136,'2014-02-26') --Since there is no end, Hence Either Fanta or Coke which ever latest record would be displayed. In this case Fanta

    INSERT INTO #TEMP VALUES ('ABC','XXX',145,'2014-02-27')

    INSERT INTO #TEMP VALUES ('ABC','XXX',175,'2014-02-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',196,'2014-03-01')

    INSERT INTO #TEMP VALUES ('ABC','XXX',112,'2014-03-02')

    INSERT INTO #TEMP VALUES ('ABC','XXX',193,'2014-03-03')

    SELECT * FROM #TEMP

    /*

    So my output would be like

    UserName DrinkValueCreatedDate

    ABC Pepsi502014-01-14

    ABC Fanta362014-01-20

    ABC Pepsi5102014-02-25

    ABC Fanta1362014-02-26

    */

    That while in a group of Coke/Fanta to HardDrink if no Pepsi record found then return Coke/Fanta record.

    I am trying on this, lets see πŸ™‚

  • JackTimber (8/23/2014)


    Suppose if i decided to tweak my result as

    /*

    I want to traverse through a loop. Loop starts with Coke/Fanta and Ends With HardDrink.

    After HardDrink it is neccessarily Coke or Fanta.

    Now over here i want the value from the column "value" for Pepsi.

    There can be a suituation where Pepsi can occur more then once in the loop between

    Coke/Fanta and HardDrink.

    */

    CREATE TABLE #TEMP (UserName varchar(20),Drink varchar(20),Value int,CreatedDate date)

    INSERT INTO #TEMP VALUES ('ABC','Coke',100,'2014-01-12') --Just one pepsi record in this loop would be displayed

    INSERT INTO #TEMP VALUES ('ABC','Fanta',50,'2014-01-13')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',50,'2014-01-14')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',75,'2014-01-18')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',36,'2014-01-20') -- No Pepsi in this loop so DISPLAY THE RECORD WITH COKE/FANTA

    INSERT INTO #TEMP VALUES ('ABC','XXX',45,'2014-01-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',75,'2014-02-04')

    INSERT INTO #TEMP VALUES ('ABC','XXX',96,'2014-02-06')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',12,'2014-02-10')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',93,'2014-02-22') -- 2 Pepsi in this loop but the one with the value 510 would be shown because it is latest

    INSERT INTO #TEMP VALUES ('ABC','XXX',101,'2014-02-22')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',150,'2014-02-23')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',510,'2014-02-24')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',175,'2014-02-25')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',136,'2014-02-26') --Since there is no end, Hence Either Fanta or Coke which ever latest record would be displayed. In this case Fanta

    INSERT INTO #TEMP VALUES ('ABC','XXX',145,'2014-02-27')

    INSERT INTO #TEMP VALUES ('ABC','XXX',175,'2014-02-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',196,'2014-03-01')

    INSERT INTO #TEMP VALUES ('ABC','XXX',112,'2014-03-02')

    INSERT INTO #TEMP VALUES ('ABC','XXX',193,'2014-03-03')

    SELECT * FROM #TEMP

    /*

    So my output would be like

    UserName DrinkValueCreatedDate

    ABC Pepsi502014-01-14

    ABC Fanta362014-01-20

    ABC Pepsi5102014-02-25

    ABC Fanta1362014-02-26

    */

    That while in a group of Coke/Fanta to HardDrink if no Pepsi record found then return Coke/Fanta record.

    I am trying on this, lets see πŸ™‚

    Anybody would like to help me with this. ? :doze:

  • Here is another suggestion on how to establish the grouping, the rest should be straight forward, select the last desired value from each group.

    😎

    CREATE TABLE #TEMP (T_ID INT IDENTITY(1,1),UserName varchar(20),Drink varchar(20),Value int,CreatedDate date)

    INSERT INTO #TEMP VALUES ('ABC','Coke',100,'2014-01-12') --Just one pepsi record in this loop would be displayed

    INSERT INTO #TEMP VALUES ('ABC','Fanta',50,'2014-01-13')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',50,'2014-01-14')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',75,'2014-01-18')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',36,'2014-01-20') -- No Pepsi in this loop so no pepsi record would be displayed

    INSERT INTO #TEMP VALUES ('ABC','XXX',45,'2014-01-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',75,'2014-02-04')

    INSERT INTO #TEMP VALUES ('ABC','XXX',96,'2014-02-06')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',12,'2014-02-10')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',93,'2014-02-22') -- 2 Pepsi in this loop but the one with the value 510 would be shown because it is latest

    INSERT INTO #TEMP VALUES ('ABC','XXX',101,'2014-02-22')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',150,'2014-02-23')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',510,'2014-02-24')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',175,'2014-02-25')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',136,'2014-02-26') --Since there is no end, Hence Either Fanta or Coke which ever latest record would be displayed. In this case Fanta

    INSERT INTO #TEMP VALUES ('ABC','XXX',145,'2014-02-27')

    INSERT INTO #TEMP VALUES ('ABC','XXX',175,'2014-02-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',196,'2014-03-01')

    INSERT INTO #TEMP VALUES ('ABC','XXX',112,'2014-03-02')

    INSERT INTO #TEMP VALUES ('ABC','XXX',193,'2014-03-03')

    ;WITH BASE_DATA AS

    (

    SELECT

    T_ID

    ,T.UserName

    ,T.Drink

    ,T.Value

    ,T.CreatedDate

    FROM #TEMP T

    )

    SELECT

    BD.T_ID

    ,ISNULL(X.T_ID,(SELECT MAX(T_ID) FROM BASE_DATA)) AS GROUP_ID

    ,BD.UserName

    ,BD.Drink

    ,BD.Value

    ,BD.CreatedDate

    FROM BASE_DATA BD

    OUTER APPLY

    (

    SELECT MIN(T_ID) AS T_ID FROM BASE_DATA B2

    WHERE B2.Drink = 'HardDrink'

    AND BD.T_ID < B2.T_ID

    ) AS X

    DROP TABLE #TEMP;

    Results

    T_ID GROUP_ID UserName Drink Value CreatedDate

    ----------- ----------- -------------------- -------------------- ----------- -----------

    1 4 ABC Coke 100 2014-01-12

    2 4 ABC Fanta 50 2014-01-13

    3 4 ABC Pepsi 50 2014-01-14

    4 9 ABC HardDrink 75 2014-01-18

    5 9 ABC Fanta 36 2014-01-20

    6 9 ABC XXX 45 2014-01-28

    7 9 ABC XXX 75 2014-02-04

    8 9 ABC XXX 96 2014-02-06

    9 14 ABC HardDrink 12 2014-02-10

    10 14 ABC Fanta 93 2014-02-22

    11 14 ABC XXX 101 2014-02-22

    12 14 ABC Pepsi 150 2014-02-23

    13 14 ABC Pepsi 510 2014-02-24

    14 20 ABC HardDrink 175 2014-02-25

    15 20 ABC Fanta 136 2014-02-26

    16 20 ABC XXX 145 2014-02-27

    17 20 ABC XXX 175 2014-02-28

    18 20 ABC XXX 196 2014-03-01

    19 20 ABC XXX 112 2014-03-02

    20 20 ABC XXX 193 2014-03-03

  • Hi Eirikur,

    I have being trying to help OP with this question with the help of your solution.

    I think the grouping in your solution is incorrect.

    If we consider the first group the grouping should end at HardDrink, but that is not the case.

    Could you please guide if i had understand your solution.

    Thanks.

  • Shadab Shah (8/23/2014)


    Hi Eirikur,

    I have being trying to help OP with this question with the help of your solution.

    I think the grouping in your solution is incorrect.

    If we consider the first group the grouping should end at HardDrink, but that is not the case.

    Could you please guide if i had understand your solution.

    Thanks.

    Whether the HardDrink falls in the next group is irrelevant, the main thing is that it marks either a beginning or an end of a group. Since HardDrink is ignored in the result set, it doesn't really matter. The thing is that I have tried to point the OP in the right direction with few hints but it looks like there isn't much of an effort on the other end.

    😎

    A last effort on this; Looping through a set is not the way to go with SQL, working on a grouped set is!

    Here is a solution based on my previous post, one of many ways of doing this.

    CREATE TABLE #TEMP (T_ID INT IDENTITY(1,1),UserName varchar(20),Drink varchar(20),Value int,CreatedDate date)

    INSERT INTO #TEMP VALUES ('ABC','Coke',100,'2014-01-12') --Just one pepsi record in this loop would be displayed

    INSERT INTO #TEMP VALUES ('ABC','Fanta',50,'2014-01-13')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',50,'2014-01-14')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',75,'2014-01-18')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',36,'2014-01-20') -- No Pepsi in this loop so no pepsi record would be displayed

    INSERT INTO #TEMP VALUES ('ABC','XXX',45,'2014-01-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',75,'2014-02-04')

    INSERT INTO #TEMP VALUES ('ABC','XXX',96,'2014-02-06')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',12,'2014-02-10')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',93,'2014-02-22') -- 2 Pepsi in this loop but the one with the value 510 would be shown because it is latest

    INSERT INTO #TEMP VALUES ('ABC','XXX',101,'2014-02-22')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',150,'2014-02-23')

    INSERT INTO #TEMP VALUES ('ABC','Pepsi',510,'2014-02-24')

    INSERT INTO #TEMP VALUES ('ABC','HardDrink',175,'2014-02-25')

    INSERT INTO #TEMP VALUES ('ABC','Fanta',136,'2014-02-26') --Since there is no end, Hence Either Fanta or Coke which ever latest record would be displayed. In this case Fanta

    INSERT INTO #TEMP VALUES ('ABC','XXX',145,'2014-02-27')

    INSERT INTO #TEMP VALUES ('ABC','XXX',175,'2014-02-28')

    INSERT INTO #TEMP VALUES ('ABC','XXX',196,'2014-03-01')

    INSERT INTO #TEMP VALUES ('ABC','XXX',112,'2014-03-02')

    INSERT INTO #TEMP VALUES ('ABC','XXX',193,'2014-03-03')

    ;WITH BASE_DATA AS

    (

    SELECT

    T_ID

    ,T.UserName

    ,T.Drink

    ,T.Value

    ,T.CreatedDate

    FROM #TEMP T

    )

    ,GROUPED_DATA AS

    (

    SELECT

    BD.T_ID

    ,ISNULL(X.T_ID,(SELECT MAX(T_ID) FROM BASE_DATA)) AS GROUP_ID

    ,BD.UserName

    ,BD.Drink

    ,BD.Value

    ,BD.CreatedDate

    FROM BASE_DATA BD

    OUTER APPLY

    (

    SELECT MIN(T_ID) AS T_ID FROM BASE_DATA B2

    WHERE B2.Drink = 'HardDrink'

    AND BD.T_ID < B2.T_ID

    ) AS X

    )

    ,DRINK_OF_THE_DAY AS

    (

    SELECT

    MAX(T_ID) AS T_ID

    FROM GROUPED_DATA GD

    WHERE GD.Drink NOT IN ('HardDrink','XXX')

    GROUP BY GD.GROUP_ID

    )

    SELECT

    GD.UserName

    ,GD.Drink

    ,GD.Value

    ,GD.CreatedDate

    FROM GROUPED_DATA GD

    INNER JOIN DRINK_OF_THE_DAY DOTD

    ON GD.T_ID = DOTD.T_ID

    DROP TABLE #TEMP;

    Results

    UserName Drink Value CreatedDate

    --------- ------- ------ -----------

    ABC Pepsi 50 2014-01-14

    ABC Fanta 36 2014-01-20

    ABC Pepsi 510 2014-02-24

    ABC Fanta 136 2014-02-26

  • Hi Eirikur,

    πŸ™‚ your example was a good learning , Thanks.

    Mr.Eirikur , Do you know some good article which are good to understand Grouped Set, Of Course google is present , but do you have some of your favorite.

    It would be great if you could share them.

  • Shadab Shah (8/23/2014)


    Hi Eirikur,

    πŸ™‚ your example was a good learning , Thanks.

    Mr.Eirikur , Do you know some good article which are good to understand Grouped Set, Of Course google is present , but do you have some of your favorite.

    It would be great if you could share them.

    No worries and you are welcome!

    I recommend you start with Itzik's Ben-Gan books T-SQL Fundamentals and then Inside Microsoft Sql. A lot of material by Itzik is available online, look for his articles.

    Another good set of material are few of the books by Joe Celko, especially SQL for Smarties, SQL Programming Style, SQL Puzzles and Answers and Thinking in Sets.

    Last but not least, more or less all the articles by Jeff Moden on SSC.

    😎

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic. Login to reply