Forum Replies Created

Viewing 15 posts - 1,996 through 2,010 (of 3,957 total)

  • RE: Catch Data between symbols in SQL

    vinu512 (2/7/2013)


    I worked it out. This is the query that would get you the results you want:

    --Creating Table

    Create Table Ex1

    (

    Id Int Identity(1,1),

    AllLevels Varchar(MAX)

    )

    --Inserting Sample...

  • RE: All Possible Combinations Loop

    akberali67 (2/8/2013)


    Hi,

    I understood the issue, it is with the concept. Mathematically, it needs more theories (Permutations, Combinations and Selections) implemented within code, I will have to buy books and read...

  • RE: Issue with crypt_gen_random

    Generating random numbers is way too important to leave to chance!

    Hence I refer you to the second link in my signature articles. 😀

    In that article, you will find a FUNCTION...

  • RE: All Possible Combinations Loop

    That's a lot of sample data! Let's look at just the first 4 rows:

    ;WITH SampleData

    ([Customer ID], Var1, Var2, Var3, Var4, Var5, Var6, Var7, Var8, Var9, Var10, Var11, Var12, Var13,...

  • RE: All Possible Combinations Loop

    akberali67 (2/7/2013)


    Hi,

    This is so amazing, I mean I ran it on a smaller dataset but this works great. I have tried SAS, R, MATLAB over the past month but I...

  • RE: Need Help with Pivooting the Columns..

    Sri8143 (2/7/2013)


    Thanks Dwain..Tat was simple.

    I thought i was good at writing SQL queries but not anymore ..I guess i was much of thinking on how to acheive the result set...

  • RE: How to add two column and the to put the result on the next row?

    ashishjain (2/6/2013)


    Hi angjoni,

    You can use below code to perform this operation:

    create table test99 (column1 int, column2 int, result int)

    insert into test99

    values

    (50,1500,0),

    (100,0,0),

    (40,0,0),

    (30,0,0)

    declare @col2 int = 1500

    select * from test99

    update test99

    set @col2...

  • RE: daily weekly monthly calculate sum

    Further to what Phil and Anthony said, you need to show your expected results exactly as they should be derived from your sample data.

    Otherwise we're not going to know how...

  • RE: Need Help with Pivooting the Columns..

    Something like this perhaps?

    SELECT id

    ,Email=MAX(CASE Typeid WHEN 1 THEN Contact END)

    ,EmailType=MAX(CASE Typeid WHEN 1 THEN TypeID END)

    ,EmailStatus=MAX(CASE Typeid...

  • RE: Nested SQL Query - % of Group Total

    Here's another option using window aggregate functions:

    ;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',...

  • RE: While/Loop Help

    wafw1971 (2/6/2013)


    Hi Phil

    Thanks for you replies, the calendar template option will be something I will use in the future but I would like to learn about loops.

    Wayne

    Better advice is learn...

  • RE: get the latest records for each group

    You just need to add a few columns to the query I provided:

    ;WITH AllCustomers AS (

    SELECT *

    ,n=ROW_NUMBER() OVER...

  • RE: how to count in sql?

    asco5 (2/7/2013)


    so i need to know the top 100 of poeple who have the most entry

    How do you want to handle tied counts?

    I'm thinking a RANK() or DENSE_RANK() might be...

  • RE: TSQL Join query help

    How about something like this to avoid the self-join? Uses Sean's setup data.

    SELECT Div_time, Unit_id

    ,TimeDifferenceMin=DATEDIFF(minute, MIN(Filled_Time), MAX(Filled_Time))

    FROM #Something

    GROUP BY Unit_id, Div_time

    HAVING MAX(Filled_Time) <> MIN(Filled_Time)

    Edit: Added...

  • RE: PIVOT data, when table design is funny

    GordonLiddy (2/7/2013)


    Hi all!

    Is there an easy way to pivot data into another table, when the design of the first table is something like this:

    ColumnProperty (nvarchar(nn))ColumnValue (sql_variant)

    =========================

    Name ...

Viewing 15 posts - 1,996 through 2,010 (of 3,957 total)